tags:

views:

284

answers:

3

I can't figure out why am i not able to play the video in my VideoView. All i'm getting a message is Cannot Play Video : Sorry, this video cannot be played.

I created an SD card for my emulator as well. Do i need to place me SD card in a particular folder in my SDK? Please comment.

Here's the layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
   android:id="@+id/LinearLayout01"
   android:layout_height="fill_parent"     
   android:paddingLeft="2px"
   android:paddingRight="2px"
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:paddingTop="2px"
   android:paddingBottom="2px"
   android:layout_width="fill_parent"
   android:orientation="vertical">

      <VideoView 
         android:layout_height="fill_parent"
         android:layout_width="fill_parent" 
         android:id="@+id/VideoView" />

</LinearLayout>

Here is the code:

package com.examples.videoviewdemo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class VideoViewDemo extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        VideoView videoView = (VideoView)findViewById(R.id.VideoView);
        //MediaController mediaController = new MediaController(this);
        // mediaController.setAnchorView(videoView);
        //videoView.setMediaController(mediaController);

        videoView.setVideoPath("/sdcard/blonde_secretary.3gp");

        videoView.start();  
    }
}

Waiting for the reply...

+1  A: 

The code seems to be flawless! Simple and plain.
So it should work on the phone. The emulator is having hard time playing videos, it happened to me too.

Try increasing the required API level to the latest, it might help!

Right click on opened project, chose Properties > Android > check the latest version on the right side...

Igor

Igor
I'm required to use 1.6 as my version here. Wonder, if you can tell me how can i update my device's OS to 2.2(Froyo)? Thanks
Maxood
I have 2.0.1 installed on my DROID. And i am trying to run this code on it but still couldn't succeed. Please let me know whats the issue?
Maxood
+1  A: 

You can access your SD card via the DDMS

poeschlorn
If an Android device(HTC, DROID, etc.) hasn't got an SD card installed then could we be able to play a video in an app on that device?
Maxood
I'm getting the following error messages in my Log cat window:07-21 03:35:47.854: ERROR/PlayerDriver(30): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported07-21 03:35:47.864: ERROR/MediaPlayer(284): error (1, -4)07-21 03:35:47.872: ERROR/MediaPlayer(284): Error (1,-4)
Maxood
+2  A: 

My guess is that your video is incompatible with Android. Try it with a different video. This one definitely works with Android. If that video works, and yours does not, then your video is not compatible with Android.

As others have indicated, please test this on a device. Video playback on the emulator requires too much power.

CommonsWare
I placed the video you suggested in my res/raw folder and changed to:video.setVideoPath("/sdcard/documentariesandyou.mp4");But still i am unable to play the video. All i am getting is the message Cannot Play Video "Sorry this video cannot be played".Whats the issue?
Maxood
@Maxood: Something is up with your device, then. That video has played on everything I've tried it on: G1, DROID, N1, Incredible, etc. In fact, I just played it on an Incredible within the past few hours. Bear in mind that you should never hard-code `/sdcard`, particularly considering it is wrong on Android 2.2 and select other devices.
CommonsWare
We have a newly bought DROID. Now what pre-requisites there have to be to run a video file on Android?Also what should i code instead of /sdcard? Thank you
Maxood
@Maxood: "Now what pre-requisites there have to be to run a video file on Android?" -- for your DROID? I have no idea. Again, that video played fine on a DROID with Android 2.0 and 2.1. I haven't gotten the 2.2 update yet for the DROID and therefore have not tested the video with that combination. "Also what should i code instead of /sdcard?" -- `Environment.getExternalStorageDirectory()`.
CommonsWare
@Maxood: I would also recommend you switch to this code, to make sure it is not something with your implementation: http://github.com/commonsguy/cw-advandroid/tree/master/Media/Video/ -- this way, we can be sure the problem is limited to something about your DROID setup. Also, what version of Android is this new DROID running?
CommonsWare
The DROID OS version i have is 2.0.1. Now i am not getting the message:This video cannot be played.Despite of using the code of the above link, still the video is not being played yet.
Maxood
Updated the OS to 2.2. Still video file is not being played in VideoView.
Maxood
Mathias Lin
Got it sorted out. import android.widget.MediaController;import android.widget.VideoView; videoSingAlong = (VideoView)findViewById(R.id.VideoView); videoSingAlong.setMediaController(mc); Uri uri = Uri.parse("android.resource://com.xxxxx.abc/" + R.raw.abc); videoSingAlong.setVideoURI(uri); videoSingAlong.start();Thanks to everybody.
Maxood