Search code examples
c#xamlwindows-phone-8mediaelement

Developing a media player for Windows Phone 8


I am to design a Media Player for Windows Phone 8. I read about using MediaLibrary (for using inbuilt player) and MediaElement ( for designing custom player).

I used MediaSource to get all files located on my phone storage using the following statements.

MediaSource media_local = MediaSource.GetAvailableMediaSources().First((source => source.MediaSourceType == MediaSourceType.LocalDevice));
using (MediaLibrary mediaLibrary = new MediaLibrary(media_local))
{
  SongCollection Songs = mediaLibrary.Songs;
  MediaPlayer.Play(mediaLibrary.Songs);
  List<Song> songslist = Songs.ToList();
  foreach (var item in songslist)
  {
    System.Diagnostics.Debug.WriteLine(item.Name);
  }
}

Next I need to design the playlist where i can show all the songs in the list songlist. I dont know what to desgn the playlist feature.

For eg. making a box which can display all the names in the playlist and how to go about displaying the Song name sequentially.


Solution

  • You could use a listbox for that...

    this is the raw xaml declration

    <ListBox x:Name="listBoxSong" FontSize="26">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Name}" Width="150"/>
                    <TextBlock Text="{Binding TrackNumber}"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    

    now just bind your list to this listbox in code .

    Like this:

    listBoxSong.ItemSource=songslist;

    This would generate a list kind of structure and also provides customization to a great extent.