When playing mp4 file on Android, video is not displayed

I am trying to display a mp4 file that I added to my resources for android ressources in res/raw , for example:

  public class Main extends RoboActivity
 {
     @InjectView (R.id.introVideo)
     private VideoView introVideo;

     private MediaPlayer player;

     @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.main);

         player = MediaPlayer.create (this, R.raw.intro_video2);
         SurfaceHolder holder = introVideo.getHolder ();
         player.setDisplay (holder);
         player.start ();

         player.setOnCompletionListener (new OnCompletionListener () {
             public void onCompletion (MediaPlayer mp)
             {
                 startActivity (new Intent (Main.this, Story.class));
                 releasePlayer ();
             }
         });
     }

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

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

     private void releasePlayer ()
     {
         if (player! = null)
         {
             player.release ();
         }
     }
 }

but all i experience is the sound of the video, the screen remains blank on my Samsung GalaxyTab. The source file is an mp4 file (H.264 AVC, 960x640, 30 frames per second) and can play perfectly with Quicktime and VLC.

I tried to zoom out and resize the original video using Handbrake, up to 480x320 and 25 frames per second, I tried several settings in the handbrake, all without success.

Something is clearly wrong with my code, or is it a video format or something else - what am I doing wrong?

Thanks in advance, Thomas.

+4
source share
2 answers

I could not get the above way of working, but I found that it worked when I only used the Android VideoView functionality, like this:

 ... String videoUri = "android.resource://my.package.path/raw/intro_video"; introVideo.setVideoURI(Uri.parse(videoUri)); introVideo.start(); ... 
+3
source

Is it a 10.1v tab (works 3.0 or 3.1) or the "old" one, running 2.2?

According to this: http://developer.android.com/guide/appendix/media-formats.html you seem to need 3.0+ for H.264 AVC. I had problems with the H 264 myself, even with the recommended values, I had to further reduce the sound. Maybe it’s worth a look.

+2
source

All Articles