Trouble streaming music

I am trying to get my app to register a music stream I have set up online. Here is what I have so far using the sample code Xamarin provides:

protected override void OnCreate (Bundle bundle)

    {

        base.OnCreate (bundle);



            SetContentView (Resource.Layout.Main);



            String url = "http://www.publicenemy.com/radio-n.php";

            MediaPlayer mediaPlayer = new MediaPlayer();

            mediaPlayer.SetAudioStreamType(Stream.Music);

            mediaPlayer.SetDataSource(url);

            mediaPlayer.PrepareAsync ();

            mediaPlayer.Start();



        // Create your application here

    }

It builds fine but when I go to deploy to test it I get an error in the app output

[MediaPlayer] start called in state 4

[MediaPlayer] error (-38, 0)

[MediaPlayer] Error (-38,0)

[MediaPlayer] error (1, -2147483648)

[MediaPlayer] Error (1,-2147483648)

Pretty new to Android app development, not sure what's wrong here. Any help will be appreciated!

Best Answer

Answers

  • KlutchSCKlutchSC USMember

    On final thing, I found the graph display of the states the stream must be in for each step to work (found here:http://developer.android.com/reference/android/media/MediaPlayer.html)

    However, NONE of the operations shown actually work with the MediaPlayer class. Im extremely lost and the documentation for the media player is complete crap as it leads me nowhere.

    Maybe someone could simply explain this diagram. I also checked the error codes above.
    -38 means that the start was called before the stream is prepared, but according to the documentation Async should return it immediately, so I'm not sure why this is breaking.
    -1, -21474... was not coming up with anything was I searched, I'm sorry

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭
    edited May 2013

    If you are using PrepareAsync() instead of Prepare(), you should only Start() after receiving the Prepared event.

    You may find the Media Playback Guide document easier to start with than the API reference link you mentioned above. This is true in general for Android documentation.

  • KlutchSCKlutchSC USMember

    Thank you, I actually found that site too and began looking at it. I noticed it says that in order to send it from an initialized state into a prepared state I need to use the method of MediaPlayer.OnPreparedListener
    but first of all there is no call that can be made to this method, doesn't exist in Xamarin. Second, I can call the method
    MediaPlayer.SetOnPreparedListener ()
    but this is telling me that it must take in a parameter of type listener. I have no idea what this is and no idea where to look.

    Like I said before, I am very new to app development and the references are not the same on this page as the ones Xamarin uses.

  • kingleroygkingleroyg ZAMember ✭✭

    Hey KlutchSC, Did you find a solution too your problem ? If so could you github your code or atleast show us a sample. I am also facing the same problem

    Thanks

Sign In or Register to comment.