Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass List <AudioTrack> from class to class AudioPlayer

The site is an example of microsoft for Windows Phone 7, namely: Background Audio Player Sample or Sample In this example, the playlist is formed in the class AudioPlayer as a list of

    private static List<AudioTrack> _playList = new List<AudioTrack>
{
    new AudioTrack(new Uri("Kalimba.mp3", UriKind.Relative), 
                    "Kalimba", 
                    "Mr. Scruff", 
                    "Ninja Tuna", 
                    null),

    new AudioTrack(new Uri("Maid with the Flaxen Hair.mp3", UriKind.Relative), 
                    "Maid with the Flaxen Hair", 
                    "Richard Stoltzman", 
                    "Fine Music, Vol. 1", 
                    null),

    new AudioTrack(new Uri("Sleep Away.mp3", UriKind.Relative), 
                    "Sleep Away", 
                    "Bob Acri", 
                    "Bob Acri", 
                    null),

    // A remote URI
    new AudioTrack(new Uri("http://traffic.libsyn.com/wpradio/WPRadio_29.mp3", UriKind.Absolute), 
                    "Episode 29", 
                    "Windows Phone Radio", 
                    "Windows Phone Radio Podcast", 
                    null)
};

And I have a question, for example if I make it in MainPage.cs:

 private static List<AudioTrack> playList2 = new List<AudioTrack>
{
    new AudioTrack(new Uri("http://myserver.com/tracks/track1.mp3", UriKind.Absolute), 
                    "MyTrack1", 
                    "Windows Phone Radio", 
                    "Windows Phone Radio Podcast", 
                    null),

    new AudioTrack(new Uri("http://myserver.com/tracks/track2.mp3", UriKind.Absolute), 
                    "MyTrack2", 
                    "Windows Phone Radio", 
                    "Windows Phone Radio Podcast", 
                    null),

    new AudioTrack(new Uri("http://myserver.com/tracks/track3.mp3", UriKind.Absolute), 
                    "MyTrack3", 
                    "Windows Phone Radio", 
                    "Windows Phone Radio Podcast", 
                    null)
};

which will be links to several Internet radio in the class MainPage, is it possible to transmit in AudioPlayer. Advise what to do, where to dig. Help me

like image 323
arsenium Avatar asked Oct 07 '11 21:10

arsenium


1 Answers

Write the information to IsolatedStorage or a database from the client application, then read it from the AudioPlayer agent.

To clarify: Whether you're playing local files or stream files you will communicate with the Agent by writing that info to a DB table or a file in IsolatedStorage. Say you have a database with a table named Playlist.

From your app or MainPage.xaml.cs (or viewmodel) write the data to the playlist table. Then issue BackgroundAudioPlayer.Instance.Play();

Then, in the AudioPlayerAgent read from the Playlist table to get the data to create an AudioTrack.

update: Originally I was using IsolatedStorage for this and it worked, now I'm using SterlingDB. This works pretty well as I can write play list records out to SterlingDB in my client app and read them one at a time in the Agent as the currentTrackIndex is manipulated, all without having to create an SterlingDB index.

like image 142
Derek Beattie Avatar answered Sep 20 '22 17:09

Derek Beattie