I'm making a page with LongListboxSelector
which shows audiotracks. Each item has Button
"play" and TextBlock
with artist and title info. I'm using BackgroundAudioPlayer
. My desire is to make next: when track is playing - image of the Button
is "pause", when track is over - make its Button
image "play", and make the next track's Button
image "pause" (next track plays automatically). I tried somethink likes this
public AudioListPage() { InitializeComponent(); BackgroundAudioPlayer.Instance.PlayStateChanged += Instance_PlayStateChanged; } void Instance_PlayStateChanged(object sender, EventArgs e) { if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.Stopped) { IEnumerable buttons = AudioLLS.Descendants<Coding4Fun.Phone.Controls.RoundButton>(); var test = new BitmapImage(new Uri(@"/Images/appbar.transport.pause.rest.png", UriKind.Relative)); foreach (Coding4Fun.Phone.Controls.RoundButton item in buttons) { if (item.ImageSource == test) { MessageBox.Show("in new image"); item.ImageSource = new BitmapImage(new Uri(@"/Images/appbar.transport.play.rest.png", UriKind.Relative)); buttons.GetEnumerator().MoveNext(); item.ImageSource = new BitmapImage(new Uri(@"/Images/appbar.transport.pause.rest.png", UriKind.Relative)); } } } }
PlayState.Stopped
fires when track ends, and next is going to start. I tried to take all buttons in my LLS using LinqToVisualTree
helper in IEnumerable buttons = AudioLLS.Descendants<Coding4Fun.Phone.Controls.RoundButton>()
and compare their images with test
. But as I can see - I'm doing it wrong, because in block if(item.ImageSource == test)
my app never comes. Please, tell me, what I'm doing wrong? And if my way to solve the problem is bad - please, tell me how to do it in easy way.
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog