Android VideoView Cannot play video mp4 - android

I used the Android VideoView to play a video file via HTTP. My problem is my phone prompts "Cannot play video Sorry, this video cannot be played." when playing a mp4 file from HTTP. But it is ok when playing another mp4 video file.
When used in a newer phone, like Samsung Galaxy S, my program can play both mp4 video file from HTTP successfully.
My phone:
Samsung GT-S5830
Android version: 2.3.4
Display: 320x480.
Video file 1 (OK):
Video Codec: H.264
Resolution: 640x360
Others: 16:9, 340kbps, 29.92fps
Audio Codec: AAC, 44kHz 96kbps Stereo.
Video file 2 (Fail):
Video Codec: H.264
Resolution: 640x360
Others: 16:9, 993kbps, 25fps
Audio Codec: AAC 44kHz 125kbps Stereo.
Below is my code that hardcoded to play the video file 1 successfully.
public class VideoPlayActivity extends Activity {
VideoView vv;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
vv = new VideoView(this);
RelativeLayout.LayoutParams param1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
param1.addRule(RelativeLayout.CENTER_IN_PARENT);
vv.setOnErrorListener(new OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.d("Dbg", "OnErrorListener: onError: " + what + ", " + extra);
return false;
}
});
RelativeLayout layout = new RelativeLayout(this);
layout.addView(vv, param1);
setContentView(layout);
playContent();
}
private void playContent() {
String path = "http://rmcdn.2mdn.net/MotifFiles/html/1248596/android_1330378998288.mp4";
vv.setVideoPath(path);
vv.requestFocus();
vv.start();
}
}
The error log when playing video file 2 is as below:
11-19 17:49:30.119: I/VideoView(16860): start()
11-19 17:49:30.139: E/MediaPlayer(16860): error (1, -2147483648)
11-19 17:49:30.149: E/MediaPlayer(16860): Error (1,-2147483648)
11-19 17:49:30.149: D/VideoView(16860): Error: 1,-2147483648
11-19 17:49:30.149: D/Dbg(16860): OnErrorListener: onError: 1, -2147483648
It is noted that I tried to install the MX player and downloaded the both video file into my phone's SD card. The MX player can play both video files successfully.
So, can anyone help me to answer the questions below:
Why my program cannot play the video file 2 on my phone?
How can I play the video file 2 on my phone?
Thank you for your advice.

Thanks for the answer from Android MediaPlayer error (1, -2147483648).
I found the video file 2 was encoded in H.264 Main Profile, that my mobile phone cannot be played. Android Supported Media Format suggests H.264 in Baseline Profile. So after converting the video to Baseline Profile, it can be played on my phone.

Related

Android VideoView not working in sdk 4.3

I am trying to play a video from the device on a VideoView. Here is my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vView = (VideoView) findViewById(R.id.videoView);
mc = new MediaController(this);
vView.setMediaController(mc);
String new_emulator_path = "/storage/emulated/0/Download/testvid.mp4";
Uri uri = Uri.parse(new_emulator_path);
vView.setVideoURI(uri);
vView.requestFocus();
mc.show();
vView.start();
}
...
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/videoView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true" />
While using the same code on 5.1 it plays fine, but does not play in 4.3 and below. Following is the log extract:
04-30 00:28:09.141 2293-2293/com.ebook.video D/MediaPlayer: getMetadata
04-30 00:28:09.249 2293-2314/com.ebook.video E/MediaPlayer: error (1, -2147483648)
04-30 00:28:09.257 2293-2293/com.ebook.video E/MediaPlayer: Error (1,-2147483648)
04-30 00:28:09.257 2293-2293/com.ebook.video D/VideoView: Error: 1,-2147483648
I have seen many threads in regard to this error code, but could not comprehend any explanations.
EDIT: I have tried playing videos of different formats - mkv (H264 mpeg-4 AVC) , 3gp (H263), mp4 (H264 mpeg-4 AVC), flv (FLV1). Video with 3gp extension and H263 format plays fine, while others give the error message as mentioned above. Any ideas on how to resolve this ?
According to Documentation Android not support H265 before android 5.1
So I think you have issue with this. You can use ExoPlayer (Or better way ExoMedia simple wrapper around VideoPlayer & ExoPlayer).
BTW use following piece of code may helps you :
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
videoView.setVideoPath(YOUR_LOCAL_FILE_PATH);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
Log.i(TAG,"Hoooray");
}
});
videoView.start();
As I found out from your code you want to display video in emulator so first see this related post.

Video player error playing local videos

I'm trying to create a activity with a Video Player.
The problem is that in some devices (ex. Android 4.0.4) when I try to play local video the VideoView shows LogCat error :
MediaPlayer(6757): Error (1,-2147483648)
And on screen:
"Cannot play video. Sorry, this video cannot be played"
The videos be recorded with MediaRecorder and this is the config of MediaRecorder
public boolean initRecorder(){
myRecorder = new MediaRecorder();
myRecorder.setCamera(myCamera);
myRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
myRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
myRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
myRecorder.setOutputFile(getVideoFilePath()); //videopath.mp4
myRecorder.setVideoSize(size.width, size.height);
myRecorder.setPreviewDisplay(mySurfaceHolder.getSurface());
if(prepareRecorder()) return true;
else return false;
}
And played with VideoView like this:
VideoView vidDisplay = (VideoView) viewLayout.findViewById(R.id.vidDisplay);
Uri uri = Uri.parse(_imagePaths.get(position));
vidDisplay.setVideoURI(uri);
vidDisplay.setMediaController(new MediaController(_activity));
vidDisplay.requestFocus();
vidDisplay.start();
EDIT:
The problem is related to the user permissions of the video. Is there a way to create aguna videos with MediaRecorder with read permissions for everyone?
I tried to open the file and then make setReadable(true) but this not work
Can someone help me?
Thanks

android videoview error 1, -2147483648

I am getting error while playing video from asset folder and raw folder.
MediaPlayer error (1, -2147483648)
VideoView error 1, -2147483648.
I tried from asset folder as.
private String SrcPath = "file:///android_asset/aaa.mp4"; //also tried aaaa.mp3
VideoView vv = (VideoView)findViewById(R.id.videoView1);
vv.setVideoPath(SrcPath);
MediaController controller = new MediaController(this);
controller.setAnchorView(vv);
vv.setMediaController(controller);
vv.requestFocus();
vv.start();
and for raw folder i used URI as :
Uri video = Uri.parse("android.resource://com.usecontentprovider/raw/aaa.mp4");
vv.setVideoURI(video);
I got the same error message in both cases.
You can use software like avinaptic2 to get the video encoding information and make sure it matches the supported media formats in android.
A common problem I find is that videos are encoded with the wrong profiling. H.264 videos need to be encoded with Baseline level 3 or under to be played without errors or artifacts in Android.
I found the solution as I am able to play video on virtual device.
I replaced the line
Uri video = Uri.parse("android.resource://com.usecontentprovider/raw/aaa.mp4");
with
Uri video = Uri.parse("android.resource://com.usecontentprovider/raw/"+R.raw.aaa);
And its working
Using R.raw works fine but in some cases I still get the same error. Fortunately I found the solution to my problem: I had to call videoView.start() inside onPrepare().
You can check the correct answer here:
Android: 'Can't play this video'; MediaPlayer & VideoView Error 1 -38

VideoView on Archos 5 (Android 1.6) doesn't work

I'm developing an app for the Archos 5 Internet Tablet. (With Android 1.6)
I want to start a video in a VideoView within my app. On my Android emulator the following code works fine but on my Archos 5 I always get an error:
Cannot play video
Sorry, this video cannot be played.
//get current window information, and set format, set it up differently, if you need some special effects
getWindow().setFormat(PixelFormat.TRANSLUCENT);
//the VideoView will hold the video
VideoView videoHolder = (VideoView) findViewById(R.id.VideoView01);
//MediaController is the ui control hovering above the video (just like in the default youtube player).
videoHolder.setMediaController(new MediaController(this));
//assing a video file to the video holder
videoHolder.setVideoURI(Uri.parse("android.resource://mypackage/" + R.raw.testmovie));
//get focus, before playing the video.
videoHolder.requestFocus();
if(autoplay){
videoHolder.start();
}
Is there a way to run a VideoView on a archos 5?
I also tried to play the movie with the archos player. With the following code I get the error: "Cannot find the media file!".
String ACTION_LAUNCH_AVOS = "android.intent.action.LAUNCH_AVOS";
String avosCommand = "ACTION:video_play,url=videoentries:Video/testmovie.wmv,etype=resume";
final Intent startAvos = new Intent(ACTION_LAUNCH_AVOS,Uri.parse(avosCommand));
startAvos.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(startAvos);
I put the video in the Video folder of the Archos. The video runs when I open it with the file browser.
I always get the error "Cannot find the media file!", no matter what url I use.
Is there a certain folder where I have to put the video so that it can be found? And how do I get the url to that certain folder?
It would be great if you could help me!
Thanks and BR,
Thomas

Android -- Can't play any videos (mp4/mov/3gp/etc.)?

I'm having great difficulty getting my Android application to play videos from the SD card. It doesn't matter what size, bitrate, video format, or any other setting I can think of, neither the emulator nor my G1 will play anything I try to encode. I've also tried a number of videos from the web (various video formats, bitrates, with and without audio tracks, etc.), and none of those work either.
All I keep getting is a dialog box that says:
"Cannot play video"
"Sorry, this video cannot be played."
There are errors reported in LogCat, but I don't understand them and I've tried searching the Internet for further explanations without any luck. See below:
03-30 05:34:26.807: ERROR/QCOmxcore(51): OMXCORE API : Free Handle 390d4
03-30 05:34:26.817: ERROR/QCOmxcore(51): Unloading the dynamic library for OMX.qcom.video.decoder.avc
03-30 05:34:26.817: ERROR/PlayerDriver(51): Command PLAYER_PREPARE completed with an error or info PVMFErrNoResources
03-30 05:34:26.857: ERROR/MediaPlayer(14744): error (1, -15)03-30 05:34:26.867: ERROR/MediaPlayer(14744): Error (1,-15)
Sometimes I also get this:
03-30 05:49:49.267: ERROR/PlayerDriver(51): Command PLAYER_INIT completed with an error or info PVMFErrResource
03-30 05:49:49.267: ERROR/MediaPlayer(19049): error (1, -17)
03-30 05:49:49.347: ERROR/MediaPlayer(19049): Error (1,-17)
Here is the code I'm using (in my onCreate() method):
this.setContentView(R.layout.main);
//just a simple VideoView loading files from the SD card
VideoView myIntroView = (VideoView) this.findViewById(R.id.VideoView01);
MediaController mc = new MediaController(this);
myIntroView.setMediaController(mc);
myIntroView.setVideoPath("/sdcard/test.mp4");
myIntroView.requestFocus();
myIntroView.start();
Please help!
Okay, here goes. The video I've been working on in Adobe Premiere is supposed to be 480x800 (WxH), but I have the Adobe Media Encoder output the sequence as an "Uncompressed Microsoft AVI" using the "UYVY" video codec, 24fps frame rate, progressive, square pixels, and dimensions: 720x800 (WxH). This outputs a rather large file with 120px black borders on either side of the video content. I then take the video into Handbrake 0.9.4 and use the following settings (I started with the Regular->Normal preset):
Container: MP4 File
Large file size: [un-Checked]
Web-optimized: [un-Checked]
iPod 5G support: [un-Checked]
Width: 320 (this is key, any higher than 320 and it won’t work)
Height: 528
Keep Aspect Ratio: [Checked]
Anamorphic: None
Crop Left: 120
Crop Right: 120
Everything under the "Video Filter" tab set to "Off"
Video Codec: H.264(x264)
Framerate: same as source
2-Pass Encoding: [Checked]
Turbo first pass: [un-Checked]
Avg Bitrate: 384
Create chapter markers: [un-Checked]
Reference Frames: 2
Mixed References: [un-Checked]
B-Frames: 0
Motion Estimation Method: Uneven Multi-Hexagon
Sub-pixel Motion Estimation: 9
Motion Estimation Range: 16
Analysis: Default
8x8 DCT: [un-Checked]
CABAC Entropy Coding: [un-Checked]
No Fast-P-Skip: [un-Checked]
No DCT-Decimate: [un-Checked]
Deblocking: Default, Default
Psychovisual Rate Distortion: [MAX]
My main problem was that I was trying to output an mp4 file with 480x800 (WxH) dimensions. After changing the width to 320 (higher values didn't work), yet keeping the proper aspect ratio, the output video now plays without errors. I hope this helps someone else with a similar problem.
Side note: I wish the Android video restrictions were better documented.
I have had quite a bit of trouble getting many different videos to play on my phone (HTC hero). Standard 512K mp4's play (example: http://www.archive.org/details/more_animation), check with them first to make sure it's not your code.
Here's my code, from onCreate() in a sub-activity which only plays the video file:
protected VideoView mine;
protected boolean done = false;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoshow);
mine = (VideoView) findViewById(R.id.video); // Save the VideoView for touch event processing
try {
String myURI = "/sdcard/" + path + "/v/"
+ currentItem.getFile()
+ "." + currentItem.getFileType();
Uri video = Uri.parse(myURI);
mine.setVideoURI(video);
mine.start();
mine.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
result.putExtra("com.ejf.convincer01.Finished", true);
done = true;
}
});
} catch (Exception ex) {
Log.d(DEBUG_TAG, "Video failed: '" + ex + "'" );
}
I was facing this problem until I figured out that the problem was in the directory of my video. I was saving my videos to a directory that is unreachable to the video view. So every time I try to play a video it gives me error message says: "Can’t open video" or something like that.
Try and save your video to this directory which will be also visible in phone gallery.
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + "your app name ";

Categories

Resources