Help! "Cannot play video" message

All your problems with Audio, Video and Images.

Help! "Cannot play video" message

Postby MisterD » Wed Oct 06, 2010 12:10 am

I don't seem to be able to play a small MP4 video using the following code:

Code: Select all
        try {
           setContentView(R.layout.videoview);
           myVideo = (VideoView)findViewById(R.id.video);
           myVideo.setVideoPath("/tmp/test.mp4");
           mc = new MediaController(this);
           mc.setMediaPlayer(myVideo);
           myVideo.setMediaController(mc);
           myVideo.requestFocus();
        }
        catch ( Exception e ) {
           e.printStackTrace();
        }


When I run it, I get the message:

Cannot play video
Sorry, this video cannot be played.

The code above is from an Android Dev book and works with their demo MP4, mine is the right format, the file is on the SD, what am I doing wrong here? If you need it, I can get you all the info from the MP4, I can even provide you with it to try yourself if you want, I am stumped! :cry: TIA

DM
MisterD
Freshman
Freshman
 
Posts: 5
Joined: Mon Aug 30, 2010 5:33 pm

Top

Re: Help! "Cannot play video" message

Postby blundell » Thu Oct 07, 2010 1:53 pm

That looks like a pretty short tutorial. There is no callback when the video player is ready etc, Try this tutorial, I've ran it myself so I know it works :-)

http://developer.android.com/resources/ ... Video.html
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Help! "Cannot play video" message

Postby MisterD » Sun Oct 10, 2010 11:34 pm

Thanks, that sample is much better than the one I found for sure. Sadly, it doesn't work either. I've tried it with a different video file, both MP4 and 3GPP, neither plays. It throws this exception now:

Code: Select all
E/VideoTestApp(  321): error: Prepare failed.: status=0x1
E/VideoTestApp(  321): java.io.IOException: Prepare failed.: status=0x1
E/VideoTestApp(  321):   at android.media.MediaPlayer.prepare(Native Method)


I looked that one up, found some site that said it was permissions and to embed the video in the res/raw folder and load them up using FileDescriptor, so I tried that. No luck, but a new exception:

Code: Select all
E/VideoTestApp(  309): error: setDataSourceFD failed.: status=0x80000000
E/VideoTestApp(  309): java.io.IOException: setDataSourceFD failed.: status=0x80000000
E/VideoTestApp(  309):   at android.media.MediaPlayer.setDataSource(Native Method)


The videos aren't that big or complex, what am I doing wrong?
MisterD
Freshman
Freshman
 
Posts: 5
Joined: Mon Aug 30, 2010 5:33 pm

Re: Help! "Cannot play video" message

Postby blundell » Mon Oct 11, 2010 8:58 am

You'll have to show me your whole code, cos as I said the example I gave you does work, I've used it myself!
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Help! "Cannot play video" message

Postby MisterD » Mon Oct 11, 2010 11:50 am

It's basically a slimmed down version of the API demo now, although the first attempt I made was with the unaltered demo code, so makes me start thinking there is something wrong with the videos themselves, but I have tried several now, always the same error. Here is the code as it sits now:

Code: Select all
public class VideoTestApp extends Activity implements
OnBufferingUpdateListener, OnCompletionListener,
OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback {
    private static final String TAG = "VideoTestApp";
    private int mVideoWidth;
    private int mVideoHeight;
    private MediaPlayer mMediaPlayer;
    private SurfaceView mPreview;
    private SurfaceHolder holder;
    private boolean mIsVideoSizeKnown = false;
    private boolean mIsVideoReadyToBePlayed = false;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.mediaplayer);
        mPreview = (SurfaceView) findViewById(R.id.surface);
        holder = mPreview.getHolder();
        holder.addCallback(this);
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    private void playVideo() {
        doCleanUp();
        try {
            FileDescriptor fd = getResources().openRawResourceFd(R.raw.test).getFileDescriptor();
            mMediaPlayer = new MediaPlayer();
            mMediaPlayer.setDataSource(fd);
            mMediaPlayer.setDisplay(holder);
            mMediaPlayer.prepare();
            mMediaPlayer.setOnBufferingUpdateListener(this);
            mMediaPlayer.setOnCompletionListener(this);
            mMediaPlayer.setOnPreparedListener(this);
            mMediaPlayer.setOnVideoSizeChangedListener(this);
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        } catch (Exception e) {
            Log.e(TAG, "error: " + e.getMessage(), e);
        }
    }
   
    public void onBufferingUpdate(MediaPlayer arg0, int percent) {
        Log.d(TAG, "onBufferingUpdate percent:" + percent);

    }

    public void onCompletion(MediaPlayer arg0) {
        Log.d(TAG, "onCompletion called");
    }

    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
        Log.v(TAG, "onVideoSizeChanged called");
        if (width == 0 || height == 0) {
            Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")");
            return;
        }
        mIsVideoSizeKnown = true;
        mVideoWidth = width;
        mVideoHeight = height;
        if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
            startVideoPlayback();
        }
    }

    public void onPrepared(MediaPlayer mediaplayer) {
        Log.d(TAG, "onPrepared called");
        mIsVideoReadyToBePlayed = true;
        if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
            startVideoPlayback();
        }
    }

    public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
        Log.d(TAG, "surfaceChanged called");
        playVideo();

    }

    public void surfaceDestroyed(SurfaceHolder surfaceholder) {
        Log.d(TAG, "surfaceDestroyed called");
    }


    public void surfaceCreated(SurfaceHolder holder) {
        Log.d(TAG, "surfaceCreated called");

    }

    @Override
    protected void onPause() {
        super.onPause();
        releaseMediaPlayer();
        doCleanUp();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        releaseMediaPlayer();
        doCleanUp();
    }

    private void releaseMediaPlayer() {
        if (mMediaPlayer != null) {
            mMediaPlayer.release();
            mMediaPlayer = null;
        }
    }

    private void doCleanUp() {
        mVideoWidth = 0;
        mVideoHeight = 0;
        mIsVideoReadyToBePlayed = false;
        mIsVideoSizeKnown = false;
    }

    private void startVideoPlayback() {
        Log.v(TAG, "startVideoPlayback");
        holder.setFixedSize(mVideoWidth, mVideoHeight);
        mMediaPlayer.start();
    }


I know I'm probably missing something simple, but I just can't see it. I appreciate you taking the time and trying to help, it's very much appreciated!
MisterD
Freshman
Freshman
 
Posts: 5
Joined: Mon Aug 30, 2010 5:33 pm

Re: Help! "Cannot play video" message

Postby blundell » Mon Oct 11, 2010 12:48 pm

Yeah the problem is with your file descriptor, res/raw and setDataSource
Try this:
Code: Select all
mMediaPlayer.setDataSource(this, Uri.parse("android.resource://com.your.package/videoname.mp4"));
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Re: Help! "Cannot play video" message

Postby MisterD » Tue Oct 12, 2010 12:21 am

Back to the first error now :cry:

Code: Select all
    E/VideoTestApp(  321): error: Prepare failed.: status=0x1
    E/VideoTestApp(  321): java.io.IOException: Prepare failed.: status=0x1
    E/VideoTestApp(  321):   at android.media.MediaPlayer.prepare(Native Method)
MisterD
Freshman
Freshman
 
Posts: 5
Joined: Mon Aug 30, 2010 5:33 pm

Re: Help! "Cannot play video" message

Postby blundell » Tue Oct 12, 2010 9:15 am

Hmm that code is the exact same as mine,

are your video's in the res/raw dir?
Try another video with this setup?
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Help! "Cannot play video" message

Postby MisterD » Tue Oct 12, 2010 11:37 am

Yes, the file is in the res/raw directory, the setDataSource() is now working fine, it's back to the prepare() method failing. I tried one other video (3GPP), same error. I am going to try to grab some more today, just to rule out a format issue or something. Any suggestions on which videos/formats to choose?
MisterD
Freshman
Freshman
 
Posts: 5
Joined: Mon Aug 30, 2010 5:33 pm

Re: Help! "Cannot play video" message

Postby blundell » Tue Oct 12, 2010 12:30 pm

I'm not at the right computer, but I think my video's were in the *.mp4 video format.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Help! "Cannot play video" message

Postby pedriyoo » Mon Jan 31, 2011 4:37 pm

Hi!
I'm stuck on the same problem, did you get around the problem?
I also get the Prepare failed.: status=0x1 error if I pass the path
and the setDataSourceFD failed.: status=0x80000000 error if I use the file descriptor.
I'm really lost here.
Thanks in advance.
pedriyoo
Freshman
Freshman
 
Posts: 2
Joined: Mon Jan 31, 2011 4:34 pm

Re: Help! "Cannot play video" message

Postby blundell » Mon Jan 31, 2011 7:25 pm

Hmm I havent looked at this in a while but did you follow the original tutorial I linked?

One thing might be to move the prepare() and the prepared listener the other way round:
Code: Select all
mMediaPlayer = new MediaPlayer();
            mMediaPlayer.setDataSource(fd);
            mMediaPlayer.setDisplay(holder);
            mMediaPlayer.setOnBufferingUpdateListener(this);
            mMediaPlayer.setOnCompletionListener(this);
            mMediaPlayer.setOnPreparedListener(this);

            // Call prepare once you have set the listeners
            mMediaPlayer.prepare();
           


Have a try
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 16 guests