3

I'm using this nu-get package to stream mp3 url in a Xamarin Android project: https://github.com/martijn00/XamarinMediaManager

I followed the instructions in the link up there... and it shows the music playing in the notification bar but it is not working (no sound and it's not even starting the song).

Code snippet:

clickButton.Click += (sender, args) =>
{
    ClickButtonEvent();
};

private static async void ClickButtonEvent()
{
    await CrossMediaManager.Current.Play("http://www.montemagno.com/sample.mp3");
}

I built the sample included in the link, and I got the same result from their sample. Also deployed on real device too, same result! Image:

Am I missing something ?

Or is the library broken ?

1
  • http://www.montemagno.com/sample.mp3 returns You don't have permission to access /sample.mp3... May 9, 2017 at 18:10

3 Answers 3

3

I ran into this using Android Emulator on Hyper-v. It turns out that the network is set to internal. So the http://www.montemagno.com/sample.mp3 could not be found. My workaround:

  1. Hyper-v -> Virtual Switch Manager, add an external network.
  2. Hyper-v -> Virtual Machines->Settings, add new hardware->Network adapter and set to external network.
  3. "Visual Studio Emulator for Android" desktop app, launch phone vm,
  4. in Visual Studio, deploy and run app.

Sound should work from external source now.

2
  • Maybe that works... but, I've actually tried on actual device and still no luck! Actually I've gone into a tough path to fix that, I made a binding into github.com/mrmaffen/vlc-android-sdk and right now I'm rewriting the CrossMediaManager and trying to fix the notification issues as well. Once I finish I will publish it on GitHub :) Cheers! Jun 7, 2017 at 18:52
  • I verified that it plays on a real devices. (A nexus 6p with current android OS v25 and a Lumia 950 windows phone). Sidenote: I was unable to build the demo github project on VS 2017. Maybe some legacy project info or a dev environment problem.
    – dskow
    Jun 14, 2017 at 18:16
1

Permissions maybe? In the project site it states that for Android:

You must request AccessWifiState, Internet, MediaContentControl and WakeLock permissions

1
  • Not permissions, I've already solved the problem by using VLC Android and binding it... then took me tons of time to add it to XamarinMediaManager. I will create a repo for the modified plugin once I have the time. Sep 8, 2017 at 9:47
1

By default example use ExoPlayerAudioService.

There are issue with url escape in ExoPlayerAudioService.GetSource method

private IMediaSource GetSource(string url)
        {
            string escapedUrl = Uri.EscapeDataString(url);
            var uri = Android.Net.Uri.Parse(escapedUrl);
            var factory =  URLUtil.IsHttpUrl(escapedUrl) || URLUtil.IsHttpsUrl(escapedUrl) ? GetHttpFactory() : new FileDataSourceFactory();
            var extractorFactory = new DefaultExtractorsFactory();
            return new ExtractorMediaSource(uri
                , factory
                , extractorFactory, null, this);
        }

string escapedUrl = Uri.EscapeDataString(url);

I.E. http://example.com/path_to_audio.mp3 will be escaped to "http%3A%2F%2Fexample.com%2Fpath_to_audio.mp3" as result HTTP error.

To fix just skip url escape.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.