0
votes

I am trying to play an audio stream from stream server in my windows phone app. I read on Microsoft Documentation that I have to reference an Audio Stream Agent.

I have these projects in my solution : enter image description here I've tried to reference a new project as Audio Streaming Agent in my Windows Phone 8.1 application

enter image description here

but I keeping receiving the error :

enter image description here

I read that I have to change the target framework, but there is no option for target framework in the AudioStreamAgent1 properties.

Also, Can I do this using an application that is not the Silverlight kind? Is there a way to do without using the Silverlight one?

1

1 Answers

3
votes

The problem is that the AudioSteamAgent is targeted at WP Silverlight, and your actual app is WP8.1 (WinRT).

To create background audio in WP8.1, you will want to use the Background Media Player.

You can find a great guide for how to get started here.

But basically (without all the boilerplate code to wire everything up), it comes down to telling the BMP what to play (code is from the link above):

BackgroundMediaPlayer.Current.SetUriSource(new Uri("ms-appx:///Assets/Media/Ring02.wma"));
BackgroundMediaPlayer.Current.Play();

And telling the OS player controls what to show, and what to do when the user interacts with them:

systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
systemmediatransportcontrol.ButtonPressed += systemmediatransportcontrol_ButtonPressed;
systemmediatransportcontrol.PropertyChanged += systemmediatransportcontrol_PropertyChanged;
systemmediatransportcontrol.IsEnabled = true;
systemmediatransportcontrol.IsPauseEnabled = true;
systemmediatransportcontrol.IsPlayEnabled = true;
systemmediatransportcontrol.IsNextEnabled = true;
systemmediatransportcontrol.IsPreviousEnabled = true;

This is all assuming that you want the user to be able to leave the app and have media continue to play. If you just want to stream audio/video while the user is in the app you can use the MediaElement control.