Android MediaPlayer Won't Stream from HTTP - android

When setting a MediaPlayer DataSource to a HTTP URL as opposed to an HTTPS URL, no audio streams and MediaPlayer error code -38 is displayed in logs.

I attempted to connect to the stream using ExoPlayer instead, and received this error. Following the docs suggestion, I added the following line of code to the application tag of my application's manifest file:
android:usesCleartextTraffic="true"
I am now able to connect to the stream at HTTP URL using both ExoPlayer and MEdiaPlayer.

Related

Mediaplayer is downloading the whole file instead of streaming it - HTTP streaming with flask backend

I am trying to make an android app that would stream audio from a webserver using http, streaming itself works with VLC and HTML "audio" tag but when trying to stream it using MediaPlayer the file just gets downloaded as a whole, not streamed.
When streamed through VLC/HTML, http response codes are 206(partial data), streaming through MediaPlayer returns 200 every time. File served on the server is in wav format(also tried m4a and mp4)
Code taking care of streaming(basically taken straight from the docs):
String url = "http://localhost:5000/song";
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioAttributes(
new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_MEDIA)
.build()
);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
mediaPlayer.start();
In your first line, change localhost to the ip address where flask is running
String url = "http://192.168.***.***:5000/song";
And run flask with the host as unspecified address (i.e. 0.0.0.0)
app.run(debug=True, host="0.0.0.0", port=5000)
Not sure why this worked, i was just messing around with different host names
Some other tips for people googling this:
Add Internet permission <uses-permission android:name="android.permission.INTERNET" /> in manifest
OP is using a route "/song" which is better solution esp if files are in folder other than static. If your files are in the static folder, you don't need a route and can reference their url directly
String url = "http://192.168.***.***:5000/static/mysong.mp3

URl not played in android MediaPlayer

I'm working media palyer app, in this i need to stream audio from URL. In my case some URL's are not streamed in some devices (Eg. Samsung Note III), after a long time i got this error message in onError() method.
E/MediaPlayer(24445): error (1, -1004)
I used the following code to pay url.
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(songPreViewUrl);
mediaPlayer.setOnPreparedListener(BackgroundAudioService.this);
mediaPlayer.setOnCompletionListener(BackgroundAudioService.this);
mediaPlayer.setOnBufferingUpdateListener(BackgroundAudioService.this);
mediaPlayer.prepareAsync();
Can any one please share the suggestion, why the urls are not streams in Samsung devices.

RTSP 1080p live-streaming android client gets error (100,0)

My new surveillance camera just arrived, so I'm trying to write an app to live stream the video from it.
Since it came with basically no documentation, I installed the 'onvifer' android app which allows you to browse the camera's capabilities. This app works fine - gets the video and allows PTZ controls, etc. It reports the streaming url as:
rtsp://192.1.0.193:554/mpeg4
I tested the stream in the VLC windows client, and it's able to stream video from that URL as well. This makes me comfortable that the network is working OK.
The camera states the feed will be 1920x1080; VLC confirms this.
The basic code in my activity:
VideoView videoView = (VideoView)this.findViewById(R.id.VideoView);
videoView.setVideoURI(Uri.parse("rtsp://192.1.0.193:554/mpeg4"));
videoView.requestFocus();
videoView.start();
I've also given the app INTERNET permissions in AndroidManifest.xml, disabled authentication on the camera, and am running on a real device (not the emulator).
When I run the app, LogCat shows this immediately:
setDataSource IOException happend :
java.io.FileNotFoundException: No content provider: rtsp://192.1.0.193:554/mpeg4
at android.content.ContentResolver.openTypedAssetFileDescriptor (ContentResolver.java).
About 15 seconds later, the app shows a "Can't play this video" modal dialog box and this is added to LogCat:
MediaPlayer error (100, 0)
AudioSystem AudioFlinger server died!
MediaPlayer error (100, 0)
VideoView Error: 100,0
I've googled everything I can think of, but haven't found anything useful.
Any thoughts?
wild-ass-guess on your logcat and the RC=100... No SDP file or no equivalent for RTSP of the 'moov atom' block required to negotiate details of the stream /container/ codec/ format... You can get the AOSP code for mediaPlayer/videoView and grep the RC value in the source.
RTSP is gnarly to debug ( note the tools links ) and not assured to run inside a NAT'd network due to UDP issues. So, to get better result, you may have to look into forcing your config to do data channel on TCP an not UDP. Or it could be other issues , of which there are many.
If you really want to investigate, some possible tools below:
Use command line and CURL client to request your stream:
Android - Java RTSP Session Mgmt package on Git
Protocol dumps for CLI RTSP sessions to Youtube RTSP/SDP streams
To pursue the issue, you may need to get into the weeds with debug tools that track details of the protocol negotiation that preceeds the MediaPlayer actually starting play on the stream. That would include learning the RFP and the protocol details.
videoView.setVideoURI(“rtsp://192.1.0.193:554/mpeg4”);
Try your app on another phone.
You may find the problem is about the mobile device.
Try this
path:"rtsp://218.204.223.237:554/mobile/1/4C024DFE77DC717D/onnuvesj43xj7t26.sdp".
See whether the code has something wrong.

Android VideoView Buffer size

I have a android application that plays HLS (Http Live Streaming) videos using VideoView.
I am using Local http proxy for forwarding http requests from VideoView to main HLS server as my stream (transport segment) is encrypted.
Flow of my application:
0. Preparing VideoView with local proxy url. ex. "http:// localhost :9878/index.m3u8"
1. VideoView sends requests to my proxy for M3U8 and ts segments.
2. Proxy forwards requests for M3u8 and ts from VideoView to HLS server.
3. Proxy checks for transport stream requests and before sending response to VideoView decrypts transport stream and sends it to VideoView.
4. VideoView plays the video stream.
This is working properly but some times i get following error:
output buffer is smaller than decoded data size Out Length
When i get this error in logcat my video becomes garbage (green video)
I see this issue usually when video stream bitrate size increases, is there any workaround for this issue?

WAV plays from file, does not play directly from URL

I have a URL that returns a 8-bit PCM, mono, 8 kHz WAV sound. When I try to play that URL via Android's MediaPlayer class, I get an error and the following in LogCat:
09-29 17:36:40.710: ERROR/PlayerDriver(562): Command PLAYER_INIT completed with an error or info PVMFFailure
09-29 17:36:40.730: ERROR/MediaPlayer(25215): error (1, -1)
The content type that the URL returns is audio/x-wav. I The error occurs after calling prepareAsync():
String uri = "http://whatever";
s_Player.setDataSource(uri);
s_Player.setAudioStreamType(AudioManager.STREAM_MUSIC);
s_Player.prepareAsync();
When I replace uri with a file path to the same sound stored in the filesystem, it plays fine. Playing the URL in the Android browser works. So it must be me somehow misusing MediaPlayer. Any ideas, please?
EDIT: it's on the emulator (for now), so permissions are not an issue.
Maybe you didn't request Internet permission in the manifest???

Categories

Resources