Musiphone - a decentralized music player

Diogen Vagrant
6 min readApr 22, 2021

After creating the music storage, it was logical to make a player to listen to songs yourself and share playlists with others. The separate network stores playlists. By default, songs are taken from the global music storage network. If you want, you can raise your networks using the necessary libraries.

I would like to divide my story into two parts:

1. Player from inside (musiphone, museria-player)

Inside, the player is a repository of information about playlists. A playlist is a list of song titles that has its own unique hash of the content that you can use to get this playlist later.

Server:

const Node = require('musiphone').Node;(async () => {
try {
const node = new Node({
port: 4000,
hostname: 'localhost',
musicStorageAddress: 'storage.museria.com:80'
});
await node.init();
}
catch(err) {
console.error(err.stack);
process.exit(1);
}
})();

Client:

const Client = require(‘musiphone’).Client;(async () => {
try {
const client = new Client({
address: ‘localhost:4000’
});
await client.init();
const title = ‘Playlist title’;
const songs = [
‘Onycs — Eden’,
‘Onycs — Shine’,
‘Onycs — Timeless’
];
// Add the playlist
const response = await client.addPlaylist(title, songs);
// Get the playlist
const playlist = await client.getPlaylist(response.hash);
}
catch(err) {
console.error(err.stack);
process.exit(1);
}
})();

Information in the network circulates depending on the free disk space on the nodes and the amount of data. If there are more playlists than there is enough space on the network, then the most rarely used ones will be deleted to free up space. On the one hand, this is good, because the network may not need very many servers, but on the other hand, the fewer of them the less guarantee of the relevance of links to playlists.

Keep in mind that the system does not guarantee permanent data storage, so for greater reliability, you can save everything to files as well. This is discussed in more detail in the second part.

The data structure in the storage is defined by metastocle. For more information, you can read the article about it

2.Player from the outside (site, android app)

From the outside the player is a website and an application for android (to be honest I haven’t tested it on many versions and devices). Despite the not very great popularity and obvious problems the choice fell on cordova, because it meets the basic requirements for the project and greatly simplifies and accelerates development.

The interface is about the same everywhere, so let’s analyze everything on the example of the site.

Create and save a playlist to the network.

First, you get to the interface with the beaver and the inactive “NEW PLAYLIST” button. This means that a new playlist is being created. To add a song, you need to find it in the music storage using the input field on the left. If the desired song is not there, then you can add it yourself by clicking on the link “MUSIC STORAGE” at the top, thereby you will help yourself and other people who will search for it in the future.

For examples, random songs that are allowed for free distribution and listening will be used. Let’s look for “Onycs - Eden”

There are a couple of options in the storage, you can listen to them and add the desired one by clicking on the plus sign. Let’s add some songs.

Now we have three songs in the playlist. You can search for them, sort them, drag them, and so on. A brown warning means that some changes have been made and if you do not save them to the network, they will disappear after clearing localStorage.

Let’s try to save everything to the network first. To do this, click “SAVE TO WEB”.

We enter the name and save it.

Now you can see that there is a tab with the name of the playlist where we can delete it or save all the contents of the song to the browser/phone cache. By the way, as you can see the same thing can be done with each individual song using the icons on the right. You can work with the player without the Internet if you have cached tracks.

We also see that the brown warning disappeared and a blue block appeared in which we have a link to the playlist. You can give this link to any person and by clicking on it they can see the same picture. Let’s create another playlist. To do this, click “NEW PLAYLIST”. Repeat the same steps and get:

We already see two playlists as well as the player itself which appeared after clicking on the block with the song.

Saving playlists to a file

For more reliability you can save playlists to files. To do this click “SAVE TO FILE”. The file will be saved in the standard m3u format and can be downloaded and listened to in any other player.

Uploading playlists

To load a playlist, click “LOAD PlAYLIST”.

In the modal window we have two options. We either download from a link or from a file. In the first case there are two types of links:

  • A static link. This is a normal hash link to a playlist in the repository: http://player.museria.com:80/musiphone/3deeb6052c5a46c05d6bec2cab5bade9
    This begs the question: why should it be loaded through the form if you can just click on it. The fact is that first, this is necessary for the mobile version and secondly, the nodes relative to which the link is created are random. This can be inconvenient when you have already configured your environment on some host, because all temporary information is stored in localStorage. Therefore, clicks on such links are convenient to get acquainted with playlists, but to form your own space you need to work with the interface of a single node, for example, the default one: player.museria.com
  • Dynamic link. Such a link is not associated with the repository, it must contain the path to any valid m3u file/server response on the Internet. The content will be automatically transformed into the app playlist. Every 10 seconds there will be a new background request for this link in case the data has changed and you need to update the list. The dynamic link is converted to the following format, so that it can also be shared: http://player.museria.com:80/musiphone/external:someUrlHash

In the case of the file, we use the same m3u format.

All m3u files must be valid, but don’t have to contain file paths. Song titles are enough to download.

Configs

Everything you configure in the player is stored in localStorage. To save this information to a file(json), use the “SAVE CONFIG” button, and to load — “LOAD CONFIG”. You can configure different groups of playlists, the volume level of the player, and so on by creating different configs. Here, for example, is the config for you from the examples in this article.

You can help the project by running at least one node for the music storage on your server with a space of 50–1000gb, from 2GB of RAM and 2 cores. The more nodes the more songs are available.

Or to run a node for the player network: from 300 MB of free space, 1 GB of RAM, 1 core.

The more nodes the longer links live.

Telegram group in English, or just PM me @ortex there.

--

--