Advertisement
OhioJoe

mm-music.js

Aug 24th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // Program to update MagicMirror Index.php code
  2.    
  3.     // This function will be called when a track playback is started
  4.  
  5.  function updateText(data){
  6.  
  7.         // Show what contains the data on the console
  8.         console.log(data)
  9.  
  10.         // Get the track from the data
  11.         var track = data.tl_track.track;
  12.    
  13.         // Get the track name and album name
  14.         var trackName = track.name;
  15.         var albumName = track.album.name;
  16.  
  17.         // A song can have more than one artist so we will iterate all the artists
  18.       var artists = "";
  19.                 for (var i=0; i<track.artists.length; i++){
  20.                         // Add the current artist name to artists
  21.             if( i > 0 )
  22.                 artists += ', ';
  23.                
  24.                 artists += track.artists[i].name;
  25.                 }
  26.                
  27.     // added var to add <div/>   Found it in main.js                
  28.        var updateWithText = "$('<div/>').html(text)";
  29.      
  30.     // Build our HTML manually and set the music div to it:          
  31.             $('.music').updateWithText( 'Track: ' + trackName + ' '  + 'Album: ' + albumName + '<br>' + 'Artist: ' + artists + '</span');
  32.  
  33.     }  //end of function
  34.  
  35.  
  36. //Code product of 9and3r  -Thanks so much!!
  37.  
  38. function updateTitle(data){
  39.               $('.music').updateWithText( 'Track: ' + data.title);
  40.         }
  41.        
  42.         // We set that when the event:trackPlaybackStarted is fired, updateText() will be executed
  43.         // But never updates on song change - will update if I select a new song on phone app.
  44.     var mopidy = new Mopidy({webSocketUrl: "ws://192.168.1.94:6680/mopidy/ws/"});  
  45. //  var mopidy = new Mopidy();
  46.     mopidy.on("event:trackPlaybackStarted", updateText);
  47.     mopidy.on("event:streamTitleChanged", updateTitle);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement