Android VideoView not playing sample video on T-Mobile G2 (just audio)

Tags: , ,



What I’m trying to do is play the first video retrieved from the external SD card, which on my T-Mobile G2 turns out to be the sample video for the phone. Now I assumed that since it plays in the phones video player, that it’d have no problems playing in the VideoView in my test app.

However, all I get is the audio playing. I’m pretty sure the code is all fine. After all, it’s pretty simple.

All I can think is that maybe the phones video player uses some native playback function which supports more video formats?

I’ve also tried playing the mv4 (actually an MP4 file) and the 3gp files from this site http://support.apple.com/kb/HT1425, but pushing them on to the emulator SDCard. Both of them exhibit the same problem – there is audio, but no video!

Could I be missing a permission somewhere or what could explain this behavior?

Code:

public class Video extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);  
        
        setContentView(R.layout.video);
        
        // Get the external storage state
        String state = Environment.getExternalStorageState();
        
        // Check if we can read it in
        if (Environment.MEDIA_MOUNTED.equals(state)==false&&
         Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)==false)
        {
         // We can't read from the memory card, so warn and return;
         Toast toast = Toast.makeText(this, 
           "The SD card is either missing or not in a readable state.", Toast.LENGTH_LONG);
         toast.show();
         return;
        }
        
        // Get a cursor to the video files
        Cursor cc = this.getContentResolver().query(
          MediaStore.Video.Media.EXTERNAL_CONTENT_URI, 
          null, null, null, null);

        // Get the video column index
        int videoIDColumn = cc.getColumnIndex(MediaStore.Video.VideoColumns._ID);
        
        // Iterate though the videos pointed to by the cursor
        if (cc.moveToFirst())
        {
          int videoID = cc.getInt(videoIDColumn);
          Uri videoPath = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,String.valueOf(videoID));
          
          // Log and add an image to the view
          Log.i("Video Found",videoPath.toString());
          
          VideoView videoView = (VideoView)findViewById(R.id.VideoTest);
          videoView.setVideoURI(videoPath);
          videoView.start();
        }
        else
        {
         Toast toast = Toast.makeText(this, 
           "Can't find a video to play.", Toast.LENGTH_LONG);
         toast.show();
        }
    }
}

Update

I’ve tried using android 1.5 and 1.6, but the problem still persists.

Also, I just checked logcat and there are no errors for any of the other files, but for the .3gp I get this error:

07-02 10:53:31.181: INFO/Video Found(235): content://media/external/video/media/2
07-02 10:53:31.383: VERBOSE/VideoView(235): reset duration to -1 in openVideo
07-02 10:53:31.541: INFO/ActivityManager(58): Displayed activity com.dvl.testing/.screens.Video: 533 ms (total 533 ms)
07-02 10:53:31.693: WARN/PlayerDriver(31): Using generic video MIO
07-02 10:53:31.883: ERROR/SW_DEC(31): PV SW DECODER is used for MPEG4
07-02 10:53:31.922: DEBUG/AudioSink(31): bufferCount (4) is too small and increased to 12
07-02 10:53:32.322: INFO/ARMAssembler(58): generated scanline__00000077:03010104_00000004_00000000 [ 22 ipp] (41 ins) at [0x2166f8:0x21679c] in 3379159 ns

Answer

Wow, sometimes I hate the android documentation.

Turns out that in my case, I was specifying a background colour for the VideoView in xml, but instead of being the background colour which I assumed would show while the video is loading / buffering, it was in fact the foreground and being rendered over the video which was playing perfectly behind it! lol

So changing:

<VideoView 
  android:id="@+id/VideoTest" 
  android:background="#FF00FF00" 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
</VideoView>

to

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

Works a treat for me and my videos are now showing! 🙂

Hope this helps someone!

Andy.



Source: stackoverflow