Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4586630
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:39:58+00:00 2026-05-21T21:39:58+00:00

I am trying to play a .mp4 file using the android.media.MediaPlayer class.I am trying

  • 0

I am trying to play a .mp4 file using the android.media.MediaPlayer class.I am trying it out on the emulator.Unfortunately all i see is a blank screen when running the application.

I have placed the file testmp4 in the folder mnt/sdcard/

Here is the code that i am using.Can someone tell me what i am doing wrong?

package com.mediaplayer;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class MyPlayBack extends Activity implements SurfaceHolder.Callback{
    /** Called when the activity is first created. */
    private  MediaPlayer mediaPlayer;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         mediaPlayer=new MediaPlayer();
        SurfaceView surface=(SurfaceView)findViewById(R.id.surface);
        SurfaceHolder holder=surface.getHolder();
        holder.addCallback(this);
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        holder.setFixedSize(400, 300);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub



    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        mediaPlayer.setDisplay(holder);
        try {
            mediaPlayer.setDataSource("/sdcard/testmp4.mp4");
            mediaPlayer.prepare();
            mediaPlayer.start();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        mediaPlayer.release();
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<SurfaceView
 android:id="@+id/surface"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_gravity="center"
 />
</LinearLayout>

Edit:Lately i found that when I keep the application running for a long time.I see the blank white screen.But when i press the back button I can see that the frame of the video clip for a sec before the application closes.I think that the video is playing behind the white screen.How to bring it upfront.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:39:58+00:00Added an answer on May 21, 2026 at 9:39 pm

    Why re-invent the wheel? Use VideoView, it is meant for that. If you want to see how to see it right, look at the VideoView source.

    Also, emulators are no-good for using video. Use a real device for video application development / testing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to play continuous stream using android mediaplayer.but am not able to
I am trying to play audio buffered sound (.wav) using AudioTrack. Please see the
I'm trying to play a movie (ripped from a DVD using handbreak to mp4
I am trying to play mp4 video using html5 video tag. But in FF
I am trying to play and audio file using DirectX dll. Audio.FromFile(Message 1.mp3).Play(); But
I am trying to play video(.mp4) in my app using following code. NSString *doc
I am trying to play .mp4 file which is on Darwin server I have
I'm trying to play with inter-process communication and since I could not figure out
I am trying to play a *.wav file with Java. I want it to
I'm trying to play only part of a sound using FMOD, say frames 50000-100000

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.