Question

I'm trying to make a small radius with the AudioPlaybackAgent as Microsoft show in their Samples In the sample we have a list of adudios:

private static List<AudioTrack> _playList = new List<AudioTrack>
{
    new AudioTrack(new Uri("http://000.000.000.000/radio1.mp3", UriKind.Absolute),
    "Radio 1", null, null, null, null, EnabledPlayerControls.Pause),

    new AudioTrack(new Uri("http://000.000.000.000/radio2.mp3", UriKind.Absolute), 
    "Radio 2", null, null, null, null, EnabledPlayerControls.Pause)
};

And here I would play the tracks:

private void PlayTrack(BackgroundAudioPlayer player)
{
    player.Track = _playList[VARIABLE];
}

On "VARIABLE" I want to put a variable that change depending the page I open in the main project. How I can do it? I tried a lot of things without exit. Thnks!!

Was it helpful?

Solution

The final answer: If you not need to use the audio in background you can simple use the media element, but if you want to use it you CAN NOT interactuate between the background agent and the main project with public variables, you must be work with Tag property of the audio player to store and get data, if this don't work you can try IsolatedStorge - Mutex.

OTHER TIPS

If you want to play music based on what page the user is viewing, you should use the MediaElement control instead of an audio agent. You can set the source of the MediaElement to be whatever you want. You can do this is XAML or code

<MediaElement x:Name="MyMediaElement" Source="{Binding YourProperty}"/>

MyMediaElement.Source = new Uri(model.YourProperty);
MyMediaElement.Volume = 1;
MyMediaElement.Play();

You can also set the track for the BackgroundAudioPlayer from your application

var track = new AudioTrack(
        new Uri(AudioUri),
        "Some song",   // can be an empty string if no song title
        "Some artist", // can be an empty string if no artist name
        null, // album
        null, // album art
        );

BackgroundAudioPlayer.Instance.Track = track;
BackgroundAudioPlayer.Instance.Play();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top