La lecture de la vidéo utilisation du lecteur multimédia de la classe

Je suis en train de faire l'utilisation de MediaPlayer classe pour la lecture d'un fichier vidéo. Le problème est que la vidéo n'est pas affichée si je peux entendre le son de la vidéo à jouer.

Voici le code d'activité

public class MainActivity extends Activity implements OnClickListener {

private SurfaceView surfaceView;
private Button btnPlay;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    init();
    addListener();

}

private void init() {
    //TODO Auto-generated method stub
    surfaceView = (SurfaceView) findViewById(R.id.surfaceView1);
    btnPlay = (Button) findViewById(R.id.btnPlay);
}

private void addListener() {
    //TODO Auto-generated method stub

    btnPlay.setOnClickListener(this);
}

MediaPlayer mediaPlayer = null;

@Override
public void onClick(View v) {
    //TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.btnPlay:
        try{
        if (mediaPlayer != null) {
            mediaPlayer.reset();
            mediaPlayer.release();
        }else{
        getWindow().setFormat(PixelFormat.UNKNOWN);
        MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.wildlife);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();

        surfaceHolder.setFixedSize(176, 144);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mediaPlayer.setDisplay(surfaceHolder);
        mediaPlayer.start();}
        }catch (Exception e) {
            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
        }
        break;

    default:
        break;
    }
  }
   }

Voici le code de mise en page xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<SurfaceView
    android:id="@+id/surfaceView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" />

<Button
    android:id="@+id/btnPlay"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/surfaceView1"
    android:layout_alignTop="@+id/surfaceView1"
    android:text="@string/play" />

</RelativeLayout>

s'il vous plaît dites-moi ce qui doit être fait?
Merci à l'avance.

Vous pouvez créer votre propre surface d'affichage et appel de cette surface d'affichage de votre activité à la lecture de la vidéo. Espérons que cela peut résoudre votre problème
Je suis tombé sur cette question, tout en essayant de moi-même, de s'avère que j'ai seulement besoin d'appeler setSurface méthode et OnSurfaceAvailable de rappel.

OriginalL'auteur Chaitanya | 2013-03-14