/// <summary> /// Event handler for the metadata of the track being changed /// </summary> /// <param name="metaData">Metadata of the track</param> /// <param name="userData">Extra user provided data, if passed into MLMusicService.Start</param> void HandleMetadataChanged(MLMusicServiceMetadata metaData, IntPtr userData) { _metadataDisplay.text = String.Format("Track Title: {0}\nAlbum Name: {1}\nAlbum URL: {2}\nAlbum Cover URL: {3}\nArtist Name: {4}\nArtist URL: {5}\n", metaData.TrackTitle, metaData.AlbumInfoName, metaData.AlbumInfoUrl, metaData.AlbumInfoCoverUrl, metaData.ArtistInfoName, metaData.ArtistInfoUrl); _trackLengthMS = MLMusicService.TrackLength; Debug.LogFormat("Metadata Changed\n" + "Track Title: {0}\n" + "Album Name: {1}\n" + "Album URL: {2}\n" + "Album Cover URL: {3}\n" + "Artist Name: {4}\n" + "Artist URL: {5}\n" + "Length: {6}\n", metaData.TrackTitle, metaData.AlbumInfoName, metaData.AlbumInfoUrl, metaData.AlbumInfoCoverUrl, metaData.ArtistInfoName, metaData.ArtistInfoUrl, metaData.Length); MLMusicServiceMetadata trackMeta = new MLMusicServiceMetadata(); // Retrieve the meta information for the previous track. MLMusicService.GetMetadata(MLMusicServiceTrackType.Previous, ref trackMeta); _metadataPreviousTrack.text = string.Format("Previous: {0}", trackMeta.TrackTitle); // Retrieve the meta information for the next track. MLMusicService.GetMetadata(MLMusicServiceTrackType.Next, ref trackMeta); _metadataNextTrack.text = string.Format("Next: {0}", trackMeta.TrackTitle); }
/// <summary> /// Event handler for the metadata of the track being changed /// </summary> /// <param name="metaData">Metadata of the track</param> void HandleMetadataChanged(MLMusicService.Metadata metaData) { CurrentTrackMetadata = metaData; MLResult result = MLMusicService.GetMetadata(ref previousTrackMetadata, -1); if (!result.IsOk) { Debug.LogErrorFormat("MLMusicServiceBehavior failed to get the metadata of the previous track, disabling script. Reason: {0}.", result); enabled = false; return; } result = MLMusicService.GetMetadata(ref nextTrackMetadata, 1); if (!result.IsOk) { Debug.LogErrorFormat("MLMusicServiceBehavior failed to get the metadata of the next track, disabling script. Reason: {0}.", result); enabled = false; return; } OnMetadataChanged?.Invoke(metaData); }