Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program to update MagicMirror Index.php code
- // This function will be called when a track playback is started
- function updateText(data){
- // Show what contains the data on the console
- console.log(data)
- // Get the track from the data
- var track = data.tl_track.track;
- // Get the track name and album name
- var trackName = track.name;
- var albumName = track.album.name;
- // A song can have more than one artist so we will iterate all the artists
- var artists = "";
- for (var i=0; i<track.artists.length; i++){
- // Add the current artist name to artists
- if( i > 0 )
- artists += ', ';
- artists += track.artists[i].name;
- }
- // added var to add <div/> Found it in main.js
- var updateWithText = "$('<div/>').html(text)";
- // Build our HTML manually and set the music div to it:
- $('.music').updateWithText( 'Track: ' + trackName + ' ' + 'Album: ' + albumName + '<br>' + 'Artist: ' + artists + '</span');
- } //end of function
- //Code product of 9and3r -Thanks so much!!
- function updateTitle(data){
- $('.music').updateWithText( 'Track: ' + data.title);
- }
- // We set that when the event:trackPlaybackStarted is fired, updateText() will be executed
- // But never updates on song change - will update if I select a new song on phone app.
- var mopidy = new Mopidy({webSocketUrl: "ws://192.168.1.94:6680/mopidy/ws/"});
- // var mopidy = new Mopidy();
- mopidy.on("event:trackPlaybackStarted", updateText);
- mopidy.on("event:streamTitleChanged", updateTitle);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement