Forum Xamarin.Forms

Is it possible for MediaPlayer setDataSource to play incomming stream?

I was wondering, if it would be possible for the setDataSource to play incomming stream of parts of music each time in a loop, and not a whole file?


  • YelinzhYelinzh Member, Xamarin Team Xamurai

    If you want to play continue playing media, start a Service and control the MediaPlayer instance from there. You need to embed the MediaPlayer in a MediaBrowserServiceCompat service and have it interact with a MediaBrowserCompat in another activity.

    MediaPlayer player = new MediaPlayer();
    player.Prepared += (sender, args) => player.Start();
    await player.SetDataSourceAsync(ApplicationContext, Android.Net.Uri.Parse(Mp3));


  • mtsABCmtsABC Member ✭✭

    But this is to play music in background, I get a System.IO.Stream from another device and would like to play it directly into the setDataSource. Something like this

    System.IO.Stream mmInStream;
  • mtsABCmtsABC Member ✭✭

    I tried reading with MediaDataSource class like this

    byte[] myReadBuffer = new byte[10000];
    player.Prepared += (sender, e) =>
    player.SetDataSource(new StreamMediaDataSource(new System.IO.MemoryStream(mmInStream.Read(myReadBuffer, 0, myReadBuffer.Length))));

    But this returns the

    12-20 15:55:51.429 W/dalvikvm(32750): Unable to resolve superclass of Lmd5c539bdc79f76d0c80e6cd44011eba829/StreamMediaDataSource; (388)
    12-20 15:55:51.429 W/dalvikvm(32750): Link of class 'Lmd5c539bdc79f76d0c80e6cd44011eba829/StreamMediaDataSource;' failed
Sign In or Register to comment.