how to play video in videoview by using rtsp link - android

i am trying to play youtube videos in videoview by using rtsp url but i am getting "Can't play this error" i am using this code to play video in videoview
String SrcPath = "rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp";
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
this is my logcat error
01-14 10:41:26.844: D/libEGL(2643): loaded /system/lib/egl/libEGL_tegra.so
01-14 10:41:26.914: D/libEGL(2643): loaded /system/lib/egl/libGLESv1_CM_tegra.so
01-14 10:41:26.974: D/libEGL(2643): loaded /system/lib/egl/libGLESv2_tegra.so
01-14 10:41:27.024: D/OpenGLRenderer(2643): Enabling debug mode 0
01-14 10:41:27.204: D/dalvikvm(2643): GC_FOR_ALLOC freed 225K, 4% free 7886K/8152K, paused 27ms, total 27ms
01-14 10:41:27.634: D/MediaPlayer(2643): Couldn't open file on client side, trying server side
01-14 10:41:27.684: W/MediaPlayer(2643): info/warning (701, 0)
01-14 10:42:40.964: E/MediaPlayer(2643): error (1, -2147483648)
01-14 10:42:40.964: E/MediaPlayer(2643): Error (1,-2147483648)
01-14 10:42:40.964: D/VideoView(2643): Error: 1,-2147483648
could you please help me for this issues..

Related

Android Studio videoView - unexpected end of stream

I'm trying to play video from the URL. Everything seems fine in the first few minutes, but then it crashes and the message "Can't Play Video" occurs. My code:
videoView.setVisibility(View.VISIBLE);
videoView.setVideoPath(url);
videoView.setMediaController(mediaController);
videoView.seekTo(time);
videoView.start();
Logcat:
2020-04-03 22:02:29.572 25409-25409/com.modyf.anime_app W/InputTransport: Slow Input: 152ms so far, channel 'ClientState{7a1b727 uid 10348 pid 25409} (server)' publisher ~ publishKeyEvent: seq=1, deviceId=4, source=0x101, action=0x0, flags=0x8, keyCode=25, scanCode=114, metaState=0x0, repeatCount=0,downTime=101580658000000, eventTime=101580658000000
2020-04-03 22:03:54.751 25409-25421/com.modyf.anime_app W/MediaHTTPConnection: readAt 25214561 / 16799 => java.net.ProtocolException: unexpected end of stream
2020-04-03 22:05:11.419 25409-25421/com.modyf.anime_app W/MediaPlayerNative: info/warning (804, -1004)
2020-04-03 22:05:11.475 25409-25422/com.modyf.anime_app E/MediaPlayerNative: error (1, -1004)
2020-04-03 22:05:11.476 25409-25409/com.modyf.anime_app E/MediaPlayer: Error (1,-1004)
2020-04-03 22:05:11.476 25409-25409/com.modyf.anime_app D/VideoView: Error: 1,-1004
2020-04-03 22:05:11.604 25409-25439/com.modyf.anime_app W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:612>: EGL_BAD_ATTRIBUTE
2020-04-03 22:05:11.606 25409-25439/com.modyf.anime_app D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8937.so from current namespace instead of sphal namespace.

cordova media plugin stopped working on Android 6

I have an application on Google Play that streams music from a radio station built with the latest cordova (5.4) and I am using some of the basic plugins such as:
device plugin
crosswalk webview plugin
dialogs plugin
...
files plugin
media plugin
On Android 5.0+ the streaming works fine but recently when I upgraded my nexus on android 6.0 the streaming stopped. I updated media and file plugin to the latest versions (2.0.0 and 4.0.0 respectively), as cordova stated in their blog that these versions support the new permission checking on Android 6 but still the streaming is not working. The log gives me this:
11-24 23:53:35.347 15184-15184/com.uni.app E/chromium: [ERROR:xwalk_autofill_client.cc(170)] Not implemented reached in virtual void xwalk::XWalkAutofillClient::OnFirstUserGestureObserved()
11-24 23:53:40.395 15184-15235/com.uni.app D/MediaPlayer: setSubtitleAnchor in MediaPlayer
11-24 23:53:40.410 15184-15235/com.uni.app W/MediaPlayer: Stream has no duration and is therefore not seekable.
11-24 23:53:40.410 15184-15235/com.uni.app E/MediaPlayer: error (-2147483648, 0)
11-24 23:53:40.410 15184-15235/com.uni.app D/AudioPlayer: Send a onStatus update for the new seek
11-24 23:53:40.410 15184-15235/com.uni.app W/CordovaPlugin: Attempted to send a second callback for ID: Media951412725 Result was: {"action":"status","status":{"id":"d5334ff7-5511-ea09-b2ef-2900789941a9","msgType":3,"value":0}}
11-24 23:53:40.411 15184-15235/com.uni.app E/MediaPlayer: start called in state 0
11-24 23:53:40.411 15184-15235/com.uni.app E/MediaPlayer: error (-38, 0)
11-24 23:53:40.412 15184-15235/com.uni.app W/CordovaPlugin: Attempted to send a second callback for ID: Media951412725 Result was: {"action":"status","status":{"id":"d5334ff7-5511-ea09-b2ef-2900789941a9","msgType":1,"value":2}}
11-24 23:53:40.412 15184-15235/com.uni.app E/MediaPlayer: Attempt to call getDuration without a valid mediaplayer
11-24 23:53:40.412 15184-15235/com.uni.app E/MediaPlayer: error (-38, 0)
11-24 23:53:40.412 15184-15235/com.uni.app W/CordovaPlugin: Attempted to send a second callback for ID: Media951412725 Result was: {"action":"status","status":{"id":"d5334ff7-5511-ea09-b2ef-2900789941a9","msgType":2,"value":314586.9375}}
11-24 23:53:40.413 15184-15235/com.uni.app E/MediaPlayer: Error (-2147483648,0)
11-24 23:53:40.413 15184-15235/com.uni.app D/AudioPlayer: on completion is calling stopped
11-24 23:53:40.414 15184-15235/com.uni.app W/CordovaPlugin: Attempted to send a second callback for ID: Media951412725 Result was: {"action":"status","status":{"id":"d5334ff7-5511-ea09-b2ef-2900789941a9","msgType":1,"value":4}}
11-24 23:53:40.414 15184-15235/com.uni.app E/MediaPlayer: Error (-38,0)
11-24 23:53:40.414 15184-15235/com.uni.app D/AudioPlayer: on completion is calling stopped
11-24 23:53:40.414 15184-15235/com.uni.app E/MediaPlayer: Error (-38,0)
11-24 23:53:40.414 15184-15235/com.uni.app D/AudioPlayer: on completion is calling stopped
11-24 23:53:53.476 15184-15184/com.uni.app E/chromium: [ERROR:xwalk_autofill_client.cc(170)] Not implemented reached in virtual void xwalk::XWalkAutofillClient::OnFirstUserGestureObserved()
11-24 23:53:58.409 15184-15232/com.uni.app E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaed05f70
11-24 23:53:58.419 15184-15184/com.uni.app W/ScreenOrientationListener: Removing an inexistent observer!
11-24 23:53:58.419 15184-15184/com.uni.app E/chromium: [ERROR:runtime_javascript_dialog_manager.cc(69)] Not implemented reached in virtual void xwalk::RuntimeJavaScriptDialogManager::ResetDialogState(content::WebContents*)
11-24 23:53:58.453 15184-15184/com.uni.app D/AudioPlayer: renaming /storage/emulated/0/tmprecording.3gp to /storage/emulated/0/http://IPADDRESS:PORT/;
11-24 23:53:58.454 15184-15184/com.uni.app E/AudioPlayer: FAILED renaming /storage/emulated/0/tmprecording.3gp to /storage/emulated/0/http://IPADDRESS:PORT/;
11-24 23:53:58.465 15184-15197/com.uni.app E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb3978f90
IPADDRESS:PORT is a real http://ipaddress:port URL stream which works fine.
I now it has to do with the permissions but still no luck on finding exactly what. Going on app-info and on new permissions menu I see that the app uses Microphone, Phone and Storage permissions which are all enabled. I searched a lot and couldn't be able to find something similar.
Any help is appreciated
I found the problem, just comment this line on AudioPlayer.java
public void onPrepared(MediaPlayer player) {
// Listen for playback completion
this.player.setOnCompletionListener(this);
// seek to any location received while not prepared
//this.seekToPlaying(this.seekOnPrepared);
// If start playing after prepared
if (!this.prepareOnly) {
this.player.start();
this.setState(STATE.MEDIA_RUNNING);
this.seekOnPrepared = 0; //reset only when played
} else {
this.setState(STATE.MEDIA_STARTING);
}
// Save off duration
this.duration = getDurationInSeconds();
// reset prepare only flag
this.prepareOnly = true;
// Send status notification to JavaScript
sendStatusChange(MEDIA_DURATION, null, this.duration);
}
Checked on Github in the official repo and found this
Tried on a new sample app and worked fine on my Android 6.0 device. The solution is close to what luckakashi suggested with some extra commenting.
Seems something wrong from Crosswalk, have you try if you remove the Crosswalk plugin? And is your Android 6.0 device 64-bit?

Android audio-streaming issue on version 4.2

I am building an audio streaming app. Here is the code I use to launch the media player:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://wunh.org:8000/"), "audio/*");
startActivity(intent);
The code works fine on my Droid phone (Android 2.3.4) - it brings up the phone media player and plays the station...
But it does not work on Nexus 7 (Android 4.2) - both "Google play music" and "Video player" fail with the same error code:
12-04 11:49:25.373: E/MediaPlayer(13331): Error (1,-1004)
UPD: here is all related logcat entries:
12-04 14:04:21.573: D/MediaPlayer(17933): Couldn't open file on client side, trying server side
12-04 14:04:21.573: I/AwesomePlayer(128): setDataSource_l(URL suppressed)
12-04 14:04:21.583: V/ChromiumHTTPDataSource(128): connect on behalf of uid 10036
12-04 14:04:21.583: I/ChromiumHTTPDataSource(128): connect to <URL suppressed> #0
12-04 14:04:21.633: I/ActivityManager(481): Displayed com.google.android.music/.AudioPreview: +83ms
12-04 14:05:24.733: I/ChromiumHTTPDataSourceSupport(128): Request failed with status 4 and os_error -118
12-04 14:05:24.733: I/AwesomePlayer(128): mConnectingDataSource->connect() returned -1004
12-04 14:05:24.733: E/MediaPlayer(17933): error (1, -1004)
12-04 14:05:24.733: E/MediaPlayer(17933): Error (1,-1004)
Any suggestions will be greatly appreciated.
-Dmitry
AsyncPlayer? http://developer.android.com/reference/android/media/AsyncPlayer.html
AsyncPlayer ap=new AsyncPlayer("Player");
ap.play(this, Uri.parse(url), true, AudioManager.STREAM_MUSIC);

Android MediaPlayer error (1, -2147483648)

I have two different videos which I'm trying to load into a VideoView using
videoView.setVideoURI(Uri.parse(url));
The two videos, let them be video 1 and video 2, have the following specs (extracted using ffmpeg -i); in fact, they are two different encodings of the same video:
Video 1:
Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 90000.00 (180000/2)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '4fbfd5ece4b0932236fc234d.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isomavc1
creation_time : 2011-12-03 04:43:46
genre : Trailer
artist : Paramount Pictures
title : Captain America: The First Avenger - Theatrical Trailer #2
encoder : HandBrake 4344svn 2011111001
date : 2011
Duration: 00:02:30.67, start: 0.000000, bitrate: 6738 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 1920x800 [PAR 1:1 DAR 12:5], 6575 kb/s, 23.97 fps, 90k tbr, 90k tbn, 180k tbc
Metadata:
creation_time : 2011-12-03 04:43:46
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 159 kb/s
Metadata:
creation_time : 2011-12-03 04:43:46
Video 2:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '500416ea44aeb4b95d5ae8a0_hd.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2011-12-03 04:43:46
title : Captain America: The First Avenger - Theatrical Trailer #2
artist : Paramount Pictures
date : 2011
encoder : Lavf53.32.100
genre : Trailer
Duration: 00:02:30.69, start: 0.000000, bitrate: 2045 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 1280x720 [PAR 27:20 DAR 12:5], 1889 kb/s, 23.99 fps, 90k tbr, 180k tbn, 180k tbc
Metadata:
creation_time : 2011-12-03 04:43:46
Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 151 kb/s
Metadata:
creation_time : 2011-12-03 04:43:46
I am aware that AAC support came with Honeycomb, and therefore I tested the videos with several devices; the results are given below:
SGS II with custom 4.0.3 OS(Sensation ROM 3.4 with CF-Root kernel) - Video 1:OK - Video2:OK
SGS I with Samsung 2.3.3 OS - Video 1:error (1, -2147483648) - Video 2:OK
SGS I with custom 4.0.3 OS(ICS SGS TEAM ROM with Devil kernel) - Video 1:error (1, -2147483648) - Video 2:OK
Nexus One with original 2.3.6 OS - Video 1:See (1) below - Video 2:See (2) below
Emulator with 2.2 OS - Video 1:error (1, -2147483648) - Video 2:error (1, -2147483648)
Emulator with 4.0.3 OS - Video 1:error (1, -2147483648) - Video 2:error (1, -2147483648)
Both videos play fine in Google Chrome in a PC. It might be useful to add that in the OK case, video and audio both play correctly. In the error (1, -2147483648) case, the same log is spewed from all devices (except Nexus One):
07-18 10:25:10.996: I/MediaPlayer(17860): uri is:http://s3-eu-west-1.amazonaws.com/cf-templates-k6ohn88yswx5-eu-west-1/videos/4fbc88e7e4b0b0896e877764/4fbfd5ece4b0932236fc234d.mp4
07-18 10:25:10.996: I/MediaPlayer(17860): path is null
07-18 10:25:10.996: D/MediaPlayer(17860): Couldn't open file on client side, trying server side
07-18 10:25:39.859: D/MediaPlayer(17860): getMetadata
07-18 10:25:45.070: E/MediaPlayer(17860): error (1, -2147483648)
07-18 10:25:45.074: E/MediaPlayer(17860): Error (1,-2147483648)
07-18 10:25:45.078: D/VideoView(17860): Error: 1,-2147483648
In the (1) case, the following log is spewed from Nexus One, and the video never loads:
07-18 13:49:20.115: D/MediaPlayer(10109): Couldn't open file on client side, trying server side
07-18 13:49:20.115: I/StagefrightPlayer(68): setDataSource('http://s3-eu-west-1.amazonaws.com/cf-templates-k6ohn88yswx5-eu-west-1/videos/4fbc88e7e4b0b0896e877764/4fbfd5ece4b0932236fc234d.mp4')
07-18 13:49:20.135: I/NuHTTPDataSource(68): connect to s3-eu-west-1.amazonaws.com:80/cf-templates-k6ohn88yswx5-eu-west-1/videos/4fbc88e7e4b0b0896e877764/4fbfd5ece4b0932236fc234d.mp4 #0
07-18 13:49:20.155: I/ActivityManager(98): Displayed com.woisio/.video.VideoActivity: +450ms
07-18 13:49:20.795: I/NuCachedSource2(68): Keep alive
07-18 13:49:22.185: I/OMXCodec(68): [OMX.qcom.video.decoder.avc] allocating 4 buffers of size 460800 on input port
07-18 13:49:22.195: I/OMXCodec(68): [OMX.qcom.video.decoder.avc] allocating 8 buffers of size 2304000 on output port
07-18 13:49:25.325: D/dalvikvm(9499): GC_EXPLICIT freed 13K, 50% free 2726K/5379K, external 1625K/2137K, paused 116ms
07-18 13:49:27.525: I/NuCachedSource2(68): Keep alive
07-18 13:49:28.235: I/NuCachedSource2(68): Cache full, done prefetching for now
07-18 13:49:30.275: D/dalvikvm(9902): GC_EXPLICIT freed 8K, 50% free 2714K/5379K, external 1625K/2137K, paused 69ms
07-18 13:49:34.255: D/Finsky(9066): [1] 5.onFinished: Installation state replication succeeded.
07-18 13:49:35.855: I/NuCachedSource2(68): Keep alive
07-18 13:49:39.055: D/dalvikvm(9911): GC_EXPLICIT freed 22K, 50% free 2710K/5379K, external 1625K/2137K, paused 38ms
07-18 13:49:42.575: I/NuCachedSource2(68): Keep alive
07-18 13:49:43.285: I/NuCachedSource2(68): Keep alive
07-18 13:49:44.095: D/dalvikvm(9918): GC_EXPLICIT freed 7K, 50% free 2708K/5379K, external 1625K/2137K, paused 66ms
07-18 13:49:49.085: D/dalvikvm(9925): GC_EXPLICIT freed 15K, 49% free 3268K/6407K, external 1625K/2137K, paused 50ms
07-18 13:49:50.925: I/NuCachedSource2(68): Keep alive
07-18 13:49:54.115: D/dalvikvm(6756): GC_EXPLICIT freed 9K, 44% free 3774K/6727K, external 1625K/2137K, paused 77ms
07-18 13:49:57.685: I/NuCachedSource2(68): Keep alive
07-18 13:49:58.375: I/NuCachedSource2(68): Keep alive
07-18 13:49:59.105: D/dalvikvm(9066): GC_EXPLICIT freed 385K, 53% free 3186K/6727K, external 1625K/2137K, paused 66ms
07-18 13:50:05.955: I/NuCachedSource2(68): Keep alive
07-18 13:50:06.045: D/dalvikvm(8047): GC_EXPLICIT freed 9K, 47% free 3830K/7111K, external 1625K/2137K, paused 86ms
07-18 13:50:09.465: I/3gw.Service(488): Mobile Network not connected - not roaming
07-18 13:50:12.765: I/NuCachedSource2(68): Keep alive
07-18 13:50:13.465: I/NuCachedSource2(68): Keep alive
07-18 13:50:18.775: I/WindowManager(98): Setting rotation to 3, animFlags=0
07-18 13:50:18.795: I/ActivityManager(98): Config changed: { scale=1.0 imsi=286/2 loc=en_US touch=3 keys=1/1/2 nav=3/1 orien=2 layout=34 uiMode=17 seq=34}
07-18 13:50:18.895: D/dalvikvm(169): GC_EXTERNAL_ALLOC freed 108K, 48% free 3253K/6215K, external 5172K/5180K, paused 37ms
07-18 13:50:21.005: I/NuCachedSource2(68): Keep alive
07-18 13:50:21.265: D/dalvikvm(98): GC_EXPLICIT freed 394K, 42% free 6631K/11335K, external 4458K/5567K, paused 109ms
In the (2) case, the following log is spewed from Nexus One and as you can see, ends with an error (1, -2147483648):
07-18 13:47:03.595: D/MediaPlayer(10059): Couldn't open file on client side, trying server side
07-18 13:47:03.595: I/StagefrightPlayer(68): setDataSource('http://s3-eu-west-1.amazonaws.com/cf-templates-k6ohn88yswx5-eu-west-1/videos/4ff4514444aec3d2f9f07ead/500416ea44aeb4b95d5ae8a0_hd.mp4')
07-18 13:47:03.605: I/NuHTTPDataSource(68): connect to s3-eu-west-1.amazonaws.com:80/cf-templates-k6ohn88yswx5-eu-west-1/videos/4ff4514444aec3d2f9f07ead/500416ea44aeb4b95d5ae8a0_hd.mp4 #0
07-18 13:47:03.625: I/ActivityManager(98): Displayed com.woisio/.video.VideoActivity: +505ms
07-18 13:47:05.355: I/OMXCodec(68): [OMX.qcom.video.decoder.avc] allocating 4 buffers of size 460800 on input port
07-18 13:47:05.355: I/OMXCodec(68): [OMX.qcom.video.decoder.avc] allocating 8 buffers of size 1382400 on output port
07-18 13:47:05.365: I/NuCachedSource2(68): Keep alive
07-18 13:47:08.375: D/MediaPlayer(10059): getMetadata
07-18 13:47:08.745: D/dalvikvm(9925): GC_EXPLICIT freed 651K, 49% free 3275K/6407K, external 1625K/2137K, paused 68ms
07-18 13:47:09.205: I/3gw.Service(488): Mobile Network not connected - not roaming
07-18 13:47:11.565: I/NuCachedSource2(68): Cache full, done prefetching for now
07-18 13:47:12.095: I/NuCachedSource2(68): Keep alive
07-18 13:47:14.245: W/QCvdec(68): H264_Utils::check_header
07-18 13:47:14.245: W/QCvdec(68): check_header: start code 33
07-18 13:47:14.245: W/QCvdec(68): H264_Utils::check_header
07-18 13:47:14.245: W/QCvdec(68): check_header: start code 10
07-18 13:47:14.245: W/QCvdec(68): Parsing Error unsupported profile or level
07-18 13:47:14.245: W/QCvdec(68): ETB in Invalid State
07-18 13:47:14.245: E/OMXCodec(68): [OMX.qcom.video.decoder.avc] ERROR(0x8000100a, 0)
07-18 13:47:14.245: E/MediaPlayer(10059): error (1, -2147483648)
07-18 13:47:14.285: E/MediaPlayer(10059): Error (1,-2147483648)
07-18 13:47:14.285: D/VideoView(10059): Error: 1,-2147483648
From what I have read, the error (1, -2147483648) may correspond to unsupported codecs, corrupt metadata or incorrect file headers. If it is so, could you point me in the right direction as to use which codec? Thanks.
Just to clarify something for anyone reading this question based on the title.
When looking at the error value (1, -2147483648), the '1' value corresponds to the constant in MediaPlayer.MEDIA_ERROR_UNKNOWN.
-2147483648 corresponds to hexadecimal 0x80000000 which is defined as UNKNOWN_ERROR in frameworks/native/include/utils/Errors.h
This shows that the error's source is hard to pin down as it is quite a generic return value, thrown by codec and compatibility issues as mentioned above but also thread cancellations and several other types.
For your issue, I would recommend consulting the Android Supported Media Formats with compatible Android versions and see if the encoding type is the cause of your problem, but as mentioned above the Unknown Error response can be caused by a number of problems.
I was facing the same error on Android P (Pixel 2 XL), but all I had to do was put android:usesCleartextTraffic="true" on my AndroidManifest.xml application tag.
For streaming, the Android site has a note:
For 3GPP and MPEG-4 containers, the moov atom must precede any mdat
atoms, but must succeed the ftyp atom.
I got the same error before moving the moov atom. In order to fix this, you can use mp4Box with this command:
MP4Box -hint output.mp4
Most of my videos can stream after that. If it does not work, try this with ffmpeg:
ffmpeg -i input.flv -f mp4 -vcodec libx264 -vprofile baseline -acodec libfaac -ar 16k -ab 32k output.mp4
MP4Box -hint output.mp4
There are other tools you can find here.
I am also getting same MEDIA_ERROR_UNKNOWN error issue for playing video(rtsp).
In my case I am finding issue with my wifi. Some security reasons wifi is restricted for RTSP protocol. So that I'm facing this MEDIA_ERROR_UNKNOWN error issue. Once check with your network permissions.
When I am moving to mobile data for playing video it's working fine for me.
May be this will be helpful whoever facing same kind of error :).
Take care of the support media type and resolution of your device.
Error error (1, -2147483648) often, appear when your video media type, codecs, or resolution is not supported by your device.
Checkout the media type supported by Android in the documentation :
https://developer.android.com/guide/appendix/media-formats.html
For example, we can notice that device above 3.0 support .mp4, but not all of them support HD 720p.
If you are using MediaPlayer for playing audio, this was the case of error for me:
When performing .setDataSource() the argument I passed was a string with path to the given file. This results in all kind of exceptions I havent been able to find particular reasons for. However, when changed to FileDescriptor, according to Android Developers - .setDataSource() method, its sorted out.
I am getting the FileDescriptor object from FileInputStream.
Here is the code:
val player: MediaPlayer = MediaPlayer()
fun playRecording() {
try {
replayFileStream = FileInputStream(path)
val fd = replayFileStream?.fd
player.setDataSource(fd)
player.prepareAsync()
// start should be called from onPreparedListener
} catch (e: Exception) {
// catch exceptions
}
}
The actual start of the playback is handled in OnPreparedListener as suggested for example here: Android Media Player: Start called in state 4 error(-38,0)
.
The listener setup is following:
player.setOnPreparedListener(object: MediaPlayer.OnPreparedListener {
override fun onPrepared(player:MediaPlayer) {
player.start()
}
})
android kotlin mediaplayer
I had a similar issue. In my case the video would play fine when I downloaded it to the phone first and then played it. But when I tried to use Progressive HTTP I would get the same error noted in the OP.
I verified that the ftyp, moov and mdat atoms were in the correct order. It turned out that the problem was the the value of the ftyp field. It was set to 'qt '. I used MP4Box to extract the tracks and create a new mp4 file which had the ftyp set to 'isom'. This new file worked fine for Progressive HTTP.
I resolved this similarly to the way stated in #nam-trung's answer, however as my videos were already h264 and mp4 all I needed to do was run the following on each file:
ffmpeg -i input.mp4 -vprofile baseline output.mp4
After that, the videos all worked in VideoView when run on all devices I've tested on running API v19 through v25.
In my case the error was due to the mediaplayer not having file permissions on the locally stored video. Try storing the video onto the /mnt/sdCARD directory.
I was facing the same issue ,But what i did on my side is
Firstly i stop the media player and then Released it.
mMediaPlayer.stop();
mMediaPlayer.release();
In my case, I had Gzip Compression on the web address where the url info is. Compressed media files may not be decoded on android.
In my case, this problem was caused by a media URL with spaces! Here is the fix:
mMediaPlayer.setDataSource(source.replaceAll(" ", "%20"));
if you are using firebase , then you should copy the path(or url) from 1: Download Url which contains the https://firebasestorage.............
not from the storage location
2 : <uses-permission android:name="android.permission.INTERNET" />add this permission in manifest tag inside manifest folder
inside Rules of storage
inside Rules of storage :
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}

Android play video problem : Device Specific

I used the following code to play the video. It is working properly.
videoView = (VideoView) findViewById(R.id.VideoView);
File f=new File(Environment.getExternalStorageDirectory(), "words/"+videoname);
Uri video = Uri.parse(f.getAbsolutePath());
videoView.setVideoURI(video);
videoView.start();
But sometimes a few specific files starts to play and almose at the end of the video, it is giving error with following msg.
Cannot play video
Sorry, this video cannot be played
This is happening only when I am trying it Motorola Droid.
In the logcate it is giving following error.
04-16 11:46:12.244: WARN/MediaPlayer(7541): info/warning (1, 44)
04-16 11:46:12.244: INFO/MediaPlayer(7541): Info (1,44)
04-16 11:46:12.244: DEBUG/MediaPlayer(7541): getMetadata
04-16 11:46:12.268: DEBUG/AudioHardwareMot(7788): AudioMgr:Output 0xb538 exiting standby
04-16 11:46:14.018: WARN/AudioSystem(7112): AudioFlinger server died!
04-16 11:46:14.018: WARN/AudioSystem(7112): AudioPolicyService server died!
04-16 11:46:14.018: INFO/ServiceManager(1040): service 'media.audio_flinger' died
04-16 11:46:14.018: INFO/ServiceManager(1040): service 'media.player' died
04-16 11:46:14.018: INFO/ServiceManager(1040): service 'media.camera' died
04-16 11:46:14.018: INFO/ServiceManager(1040): service 'media.audio_policy' died
04-16 11:46:14.018: WARN/MediaPlayer(7541): MediaPlayer server died!
04-16 11:46:14.018: ERROR/MediaPlayer(7541): error (100, 0)
04-16 11:46:14.018: ERROR/MediaPlayer(7541): Error (100,0)
04-16 11:46:14.018: DEBUG/VideoView(7541): Error: 100,0
04-16 11:46:14.557: INFO/(7802): ServiceManager: 0xad80
But the same file is playing without any problem in other device. What may the problem?

Categories

Resources