Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does android web browser use for playing audio streams? MediaPlayer or something else?

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.

like image 926
Hakan Serce Avatar asked Oct 06 '22 01:10

Hakan Serce


2 Answers

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
like image 102
shkschneider Avatar answered Oct 13 '22 11:10

shkschneider


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.

like image 30
Joe Avatar answered Oct 13 '22 11:10

Joe