0
votes

Here is my problem : I have a LongListSelector which list songs from MediaLibrary and a SelectionChanged event. When the user taps on a song from the LongListSelector, it plays the song once, but then then it stops. But I'd like to play next song from the MediaLibrary once the selected song is finished

Here is my LongListSelector :

<phone:LongListSelector x:Name="llsSongs" SelectionChanged="llsSongs_SelectionChanged" Margin="0,-30,0,0">
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            <StackPanel Margin="5,5,5,5">
                <TextBlock Text="{Binding Name}" FontSize="20" Foreground="Black"/>
                <TextBlock Text="{Binding Artist}" FontSize="15" Opacity="0.75" Foreground="Black"/>
            </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>

and the SelectionChanged method

    private void llsSongs_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        Song _selectedSong = llsSongs.SelectedItem as Song;
        MediaPlayer.Play(_selectedSong);           
    }
1
Why is this tagged windows phone 7 and 8? Are you really targeting WP7?Anthony Russell
Hi and thanks for your comments, I've updated my post.CLRZ

1 Answers

-1
votes

Take a look at those articles

http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394039(v=vs.105).aspx http://developer.nokia.com/community/wiki/Audio_recording_and_playback_options_in_Windows_Phon

EDIT:

Based on your usage of the MediaLibrary and MediaPlayer XNA.Framework.Media namespace classes, you could take advantage of MediaPlayer's MediaStateChanged event.

private void MediaPlayerOnMediaStateChanged(object sender, EventArgs e)
{
    if (MediaPlayer.State == MediaState.Stopped)
    {
        MediaPlayer.Play(nextSong);
    }
}

Since your collection holds the Song's returned from MediaLibrary.Songs, SongCollection the nextSong will be the next index in your data bound collection.