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 ";
Related
I am using phonegap media to record audio as mp3. After recording, it plays fine on my Android and plays fine on Windows Media Player. However, when I try it in the browser it says that the file is corrupt.
Exact errors:
Chrome: "We cannot play this audio file right now."
Firefox: "Video can't be played because the file is corrupt."
IE: Opens the file in WMP and it plays.
I used the code from the example. http://docs.phonegap.com/en/2.6.0/cordova_media_media.md.html#media.startRecord
// Record audio
//
function recordAudio() {
var src = "myrecording.mp3";
var mediaRec = new Media(src,
// success callback
function() {
console.log("recordAudio():Audio Success");
},
// error callback
function(err) {
console.log("recordAudio():Audio Error: "+ err.code);
});
// Record audio
mediaRec.startRecord();
}
Thanks in advance.
Edit:
Here is an example. http://blrbrdev.azurewebsites.net/voice/blrbr_130419951008830874.mp3
This plays in WMP but not the browser.
The file you provided as an mp3 does not appear to be an mp3 file.
I have attached below the details of the file. As you can see it is AMR codec packed in a MPEG-4/3GPP container. I would say no current browser can decode that natively (but software like VLC can play it back).
If you are attempting to play an audio file in a browser - be it HTML5 audio for say - you need to provide a compatible format. Have a look here for a compatibility table.
This is expected behavior as stated here:
Android devices record audio in Adaptive Multi-Rate format. The specified file should end with a .amr extension.
If you want to play it in a browser/HTML5 audio tag you would need to post process the file to convert it to a valid mp3 file (add ogg audio for full browser coverage). Server side this can be done with a program called ffmpeg for example. I am no specialist of Phonegap development so I cannot point you to a valid lib that does that client side but maybe this has already been asked on SO.
File specs:
General
Complete name : C:\wamp\www\stack\sample\thisTest.mp3
Format : MPEG-4
Format profile : 3GPP Media Release 4
Codec ID : 3gp4
File size : 10.5 KiB
Duration : 4s 780ms
Overall bit rate mode : Constant
Overall bit rate : 18.0 Kbps
Performer : LGE
Encoded date : UTC 2014-04-15 00:24:57
Tagged date : UTC 2014-04-15 00:24:57
Audio
ID : 1
Format : AMR
Format/Info : Adaptive Multi-Rate
Format profile : Narrow band
Codec ID : samr
Duration : 4s 780ms
Bit rate mode : Constant
Bit rate : 12.8 Kbps
Channel(s) : 1 channel
Sampling rate : 8 000 Hz
Bit depth : 13 bits
Stream size : 7.47 KiB (71%)
Title : SoundHandle
Writing library :
Language : English
Encoded date : UTC 2014-04-15 00:24:57
Tagged date : UTC 2014-04-15 00:24:57
Firstly thanks to #Forestan06 for pointing me in the right direction.
For those of you recording on Android devices in .amr format and needing said recording in .mp3 format on your server using .Net C#, this is how I did it.
Install-Package MediaToolkit --> http://www.nuget.org/packages/MediaToolkit/
Write this code:
var fileName ="myVoice.mp3";
string fileNameWithPath = Server.MapPath("~/Voice/" + fileName);
if (request.FileName.EndsWith(".amr"))
{
var amrFileName = "myVoice.amr";
string amrFileNameWithPath = Server.MapPath("~/Voice/Amr/" + amrFileName);
request.SaveAs(amrFileNameWithPath);
var inputFile = new MediaFile { Filename = amrFileNameWithPath };
var outputFile = new MediaFile { Filename = fileNameWithPath };
using (var engine = new Engine())
{
engine.Convert(inputFile, outputFile);
}
}
else
{
request.SaveAs(fileNameWithPath);
}
I'm trying to stream my webcam live to an android VideoView over my local network. The video shows up but after a huge 15-20 seconds lag.
VLC streaming settings:
usgin HTTP
Enacpsulation: MPEG-TS
Video Codec: H-264
Resolution: 640 x 480
Bitrate: I keep changing it trying to figure out a suitable one.
VLC output string:
:sout=#transcode{vcodec=h264,vb=2000,fps=30,scale=1,width=640,height=480,acodec=none}:http{mux=ts,dst=:8080/stream} :sout-all :sout-keep
Android VideoView code:
VideoView view1 = (VideoView) findViewById(R.id.videoView1);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
MediaController mc = new MediaController(this);
mc.setMediaPlayer(view1);
view1.setMediaController(mc);
view1.setVideoURI(Uri.parse("http://192.168.1.101:8554/stream"));
view1.requestFocus();
view1.start();
I have searched everywhere for this problem but can't seem to find a solution, so any advice would be highly appreciated :)
I'm not familiar with VideoView, but why is your code referencing port 8554 when VLC is streaming on port 8080?
I recommend setting your GOP size to something around 120( --sout-x264-min-keyint <integer>), as a starting point for testing.
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.
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
I have prepared a code to just play a simple mp4 file from my res folder. The coding is something like this:
public class VideoPlayer extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
VideoView video = (VideoView)findViewById(R.id.VideoView);
Uri uri = Uri.parse("android.resource://company.software.myapp/"
+ R.raw.myvideo);
MediaController mc = new MediaController(this);
video.setMediaController(mc);
video.setVideoURI(uri);
//video.requestFocus();
video.start();
}
}
Now though there is no error in playing. The activity automatically generates a dialog saying "sorry this video cannot be played", but I can hear the audio and it plays till end. What is the problem?
Thanx a lot commonsware.com... but i found the solution to the problem... And astonishingly its the PC processor which is the culprit... I checked n a higher configuration and guess wat... it worked perfectly fine... though sometimes if we do some processing in the background the dialog box does come up but on clicking ok it starts playing the video after some time...
But i confirm that this technique of playing file from resource is ok as far as i know...
sorry to waste ur precious time in a mundane hardware problem... but hope it'll be useful for other people who get this problem...
Android supports 3gp and mp4 format, but still sometimes there are problems in playing an mp4 content.
one thing what I have found out from my research is that, this might be because the resolution problem with the video.
I think that you should re-size the resolution of your mp4 video. This might help.
I have not attempted to play a video clip out of a resource, and I am not certain that it works.
As a test, put the video clip on the SD card and use that as the source of your video.
If you get the same symptoms, then either the MP4 file has issues or it is something with your test environment (e.g., you are using the emulator and don't have a quad-core CPU).
If the SD card test works, though, then I suspect the problem is packaging it as a resource.