views:

4383

answers:

3

Hello all,

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!

+2  A: 

Videos from here definitely work, particularly "Documentaries and You". Here is a sample project that works with those videos.

Note, though, that video playback will not work well with the emulator, unless you have an extremely powerful development machine. They will play back fine on an Android device, however.

CommonsWare
Thank you for responding. I took a look at the sample code and the video site you provided and sure enough, the first video on the site, "An Army, One by One" (in mp4), worked with my code. So, the errors I'm seeing have to do with how the videos I'm working with are encoded. I will try to use the sample video I downloaded as a template for encoding my videos using Adobe Media Encoder and/or Handbrake. I will report back with success or failure. Thanks again.
borg17of20
+1  A: 

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 + "'" );
        }
Donald Scott Wilde
Thank you for replying. I took your advice and downloaded a video from the site you provided, "The Lost Kitten 1938" (512k mpeg4), and it worked flawlessly using the same exact code I provided. Thank you for this. I will try and re-encode my videos to match the specs of the downloaded sample and return to post the details. Would you perhaps know of the exact settings I should use in my encoder (I can use either Adobe Media Encoder or Handbrake)?
borg17of20
+1  A: 

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.

borg17of20
"I wish the Android video restrictions were better documented." I could not agree with you more. I've even followed your example and still can't get video to stream.
John Giotta