4

I try to render an mp4 file I added to my android ressources in res/raw like so:

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 keeps blank on my Samsung GalaxyTab. The source file is an mp4 file (H.264 AVC, 960x640, 30fps) and can be played perfectly fine with Quicktime and VLC.

I tried to downscale and resize the original video with Handbrake, down to 480x320 and 25fps, I tried several settings in handbrake, everything without success.

Is there anything obviously wrong with my code or is it the video format or something else - what am I doing wrong?

Thanks in advance, Thomas.

Thomas Keller
  • 5,933
  • 6
  • 48
  • 80
  • 1
    I tried to use different test media files from http://support.apple.com/kb/HT1425 in the mean time and _none_ showed video (some even crashed, mov and mpeg2), so I suspect something has to be wrong with my code, *sigh* – Thomas Keller Jul 08 '11 at 21:08

3 Answers3

4

I couldn't get the above way to work, but I found that it worked when I solely used the provided functionality of Android's VideoView like this:

...
String videoUri = "android.resource://my.package.path/raw/intro_video";
introVideo.setVideoURI(Uri.parse(videoUri));
introVideo.start();
...
Thomas Keller
  • 5,933
  • 6
  • 48
  • 80
2

Is it the 10.1v tab (running 3.0 or 3.1) or an "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 have had troubles with H 264 myself even with recommended values, had to downscale the sound even more. Might be worth looking in to.

David Olsson
  • 8,085
  • 3
  • 30
  • 38
  • 1
    Unfortunately this is still 2.2, not 3.0, and I need to target 2.2 anyways for phone devices. I had a look at the page you linked to earlier already, and as I interpret this you need 3.0+ for *encoding*, but no specific version for *decoding* H.264. LogCat is also unfortunately not very helpful at all and doesn't list any decoding / format errors. I could try to recode the video into H.263 if I can get my hands on a transcoder for that... – Thomas Keller Jul 08 '11 at 07:59
0

Give MediaPlayer a PreparedListener. And call MediaPlayer.start() in PreparedListener.

hsu.tw
  • 148
  • 2
  • 10