5

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

arsenium
  • 571
  • 1
  • 7
  • 20
  • 2
    Does your app only ever build the playlist in the UI? If not move the code for this into the agent (or a library shared by both) This way the agent can get more tracks to extend the playlist even if the UI isn't running. You can also reduce the amount to communication between app and agent which helps avoid further problems. – Matt Lacey Oct 11 '11 at 21:30
  • >Does your app only ever build the playlist in the UI? Yes. – arsenium Oct 12 '11 at 15:28

2 Answers2

8

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.

Derek Beattie
  • 9,429
  • 4
  • 30
  • 44
  • This is probably for local files? And if my playlist consists of links to the tracks? be like? I added some text above ... – arsenium Oct 08 '11 at 08:02
  • It's for both. If your streaming or playing local. Let me know if it doesn't make sense, I'll add more info. – Derek Beattie Oct 08 '11 at 12:38
  • Curious as to the reason for the down vote, I'd like to hear the alternatives. I got this tip from Matt Lacey, it seems to work well. – Derek Beattie Oct 11 '11 at 21:16
  • Dumb question -- how is the AudioPlayer "registered"? I can't see in that sample code where anything passes along a handle to AudioPlayer.cs. – ruffin Oct 15 '14 at 01:00
  • `AudioPlayer` is registered int he `WMAppManifest.xml`, if that's what you mean. – Derek Beattie Oct 15 '14 at 01:07
  • I do exactly the same as you mentioned. The UI app saves the list to IsolatedStorageSettings and the AudioPlayer loads it. But it always loads the same list, even if it's modified. I can see that in the UI app that it's modified, not the same list, but the AudioPlayer always loads the same. I also tried to make a class library with a class that saves/loads this data using mutex and it's no better. Could someone help me? – Lgn Oct 21 '14 at 08:34
  • That's strange, have you use the `ISETool.exe` to see what's actually being written? – Derek Beattie Oct 21 '14 at 20:08
0

It works for windows phone 8

BackgroundAudioPlayer.Instance.Track = new AudioTrack(new 
         Uri("http://traffic.libsyn.com/wpradio/WPRadio_29.mp3", UriKind.Absolute), 
        "title", "artist", "album", new Uri("albumArtUrl", UriKind.RelativeOrAbsolute));
reza.cse08
  • 5,938
  • 48
  • 39