thuan hoang

thuan hoang

  • NA
  • 1
  • 1.5k

MeidaPlayer on winphone 7

Jun 7 2013 4:51 AM
I want to do something similar to the media player in windows phone 7 where the next several song is shown. What approach I would take to accomplish this?
but it only runs on a virtual machine, when I installed it on the phone, play only 1 song
Example: previous song previous song CURRENT SONG next song next song
 
my code currently like this:
 
int i;
public MainPage()
{
InitializeComponent();
 
var library = new MediaLibrary();
lstSongs.ItemsSource = library.Songs;

var timer = new DispatcherTimer { Interval = TimeSpan.FromTicks(333333) };
timer.Tick += delegate { try { FrameworkDispatcher.Update(); } catch { } }; timer.Start();
timer.Tick += new EventHandler(currentPosition_Tick);
}
 
void currentPosition_Tick(object sender, EventArgs e)
{
switch (MediaPlayer.State)
{
case MediaState.Playing:
if (MediaPlayer.PlayPosition >= MediaPlayer.Queue.ActiveSong.Duration)
{
MediaPlayer.Stop();
i += 1;
MediaLibrary mediaLibrary = new MediaLibrary();
MediaPlayer.Play(mediaLibrary.Songs[i]);
lstSongs.SelectedIndex = lstSongs.SelectedIndex + 1;

}
break;
 
case MediaState.Paused:
break;
 
case MediaState.Stopped:
break;
}

}
 
private void SongSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{

MediaLibrary mediaLibrary = new MediaLibrary();
MediaPlayer.Play(mediaLibrary.Songs[lstSongs.SelectedIndex]);

}