سؤال

I want to ask if there is some way to get mp3 tags from music played by Windows Phone 8 media player programmatically?

I have tried to use BackgroundAudioPlayer instance, MediaPlayer from XNA framework to extract tags from song played by wp8 music player but seems I cant just get it. I ended with something like this :

var player = BackgroundAudioPlayer.Instance;
if (player.PlayerState != PlayState.Playing) return;
var track = player.Track;
ArtistTextBlock.Text = track.Artist;
SongTextBlock.Text = track.Title;

But this throws NullReferenceException if I want to assing TextBlocks with artist or song name strings.

هل كانت مفيدة؟

المحلول

If the NullReferenceException is being thrown on the assignment, you should try step through debugging to find out if your track variable is valid or if it is indeed null. One might imagine that player.Track should be player.NowPlaying or similar, but I don't know the WP8 framework that well.

Further to this, if the NullRef is only being thrown occasionally, it's entirely possible that while changing track the player doesn't have a track, thus it's returning NULL and causing this issue. Make sure the player has a track loaded, and there is an event associated with the player itself for PlayStateChanged - If you capture this event you should be able to know that when it is "Playing" you have a file loaded, and should then be able to certify that you have a track loaded.

The alternative I was thinking of is the FileInfo library with .NET, it can provide a LOT of information about files, including some of the tags. It might be possible to acquire information using that.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top