5

I have rtsp audio streams from a specific site (m.aveamuzik.com) that play within a browser. When I try to play the same stream using MediaPlayer class, I get MEDIA_ERROR_UNKNOWN (with extra=-2147483648). The error is not well documented but a little googling shows that it is most probably because of unsupported media format.

My question is, if MediaPlayer class does not support some format, how does the built-in browser play it? Also, how to use the same mechanism used by the browser in my code, instead of the MediaPlayer class?

Edit 1: @Joe

I tried the following code:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(streamURL));
startActivity(intent);

MX Player and BSPlayer showed up as options to open the file, but not anything related with AudioPreviewActivity. Actually this is quite reasonable as my URLs are rtsp, but the intent filters for AudioPreviewActivity are just for http, file and content type of URIs.

Hakan Serce
  • 11,198
  • 3
  • 29
  • 48
  • does opening the site in webview also play the audio stream? – Yenchi Nov 15 '12 at 19:17
  • Yes, opening the site in webview works just like the built in browser, as expected. – Hakan Serce Nov 15 '12 at 20:48
  • If so, I would assume it goes through HTML5Audio.java, under base/core/android/webkit/ in the AOSP source. By a quick scan it seems to use an native c++ implementation of media player object. Haven't have time to do further trace but I think at this point it's apparent that there is no way to use that mechanism in your code without going through the same route. And there is big chance that OEMs might change the AOSP code so this might not work across all devices. – Yenchi Nov 15 '12 at 21:48
  • The name of the HTML5Audio.java suggests that it handles HTML5 ` – Hakan Serce Nov 15 '12 at 22:02
  • Can you paste in the code you tried when using the media player please? Also i cannot seem to access that 3gp file. One thing i think i remember though is to get 3gp files to work in the mediaplayer you have to trick it into thinking its playing a video. – Paul Harris Nov 19 '12 at 22:15
  • I am using code from the open source jamendo player. See the lines starting with 315 for the related code here: https://github.com/telecapoland/jamendo-android/blob/master/src/com/teleca/jamendo/media/PlayerEngineImpl.java . – Hakan Serce Nov 19 '12 at 23:45

2 Answers2

3

Fact

The Browser has extra features set up to strip the video source from the page and launch it in the native player most of the time. This functionality is not built into WebView, and the native player is very picky about what needs to passed into it as a URI to be able to play it.

It works since Gingerbread in the default android browser.

Possible explaination

You probably don't use the MediaPlayer the way the android browser does. Post some code to help futher help.

Further help

  • The MediaPlayer has a lot of bugs before 4.0 (that fixed a lot a RTSP bugs).
  • The Web Audio API as described by W3C: link
  • Here is a detailed list of all media formats and protocols supported by Android: link
  • Testing page: link
  • This complete blog post also helped me about media streaming for Android: link
RobinHood
  • 10,897
  • 4
  • 48
  • 97
shkschneider
  • 17,833
  • 13
  • 59
  • 112
  • First of all thank you for the answer. Surprisingly (for me) very few people care about this subject. Actually I am using code from the open source jamendo player. See the lines starting with 315 for the related code here: https://github.com/telecapoland/jamendo-android/blob/master/src/com/teleca/jamendo/media/PlayerEngineImpl.java – Hakan Serce Nov 21 '12 at 16:52
  • I'm trying to analyse the code you proposed. If you found a good use a MediaPlayer, please then update your question for everybody to know :) – shkschneider Nov 23 '12 at 08:27
  • I will probably go on with Vitamio – Hakan Serce Nov 23 '12 at 17:44
1

If it looked like the screenshot on this other question when it is playing in the Browser, then it should be the AudioPreview Activity from the Music app.

You should be able to launch it by simply calling startActivity() with an Intent that matched one of its IntentFilter in the manifest.

Community
  • 1
  • 1
Joe
  • 14,039
  • 2
  • 39
  • 49