0

Android MediaPlayer の作成と制御に外部クラスを使用しています。

    public CycleVideo(String path, Activity activity, FrameLayout  container){
    this.path = path;
    this.activity =activity;
    this.container = container;
}

public void prepare(){

    AssetFileDescriptor  str;

    try {

        str = activity.getAssets().openFd(path);
        mp = new MediaPlayer();
        mp.setDataSource(str.getFileDescriptor());
        SurfaceView sw = new SurfaceView(activity.getApplicationContext());
        sw.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
        container.addView(sw);
        sw.setVisibility(View.VISIBLE);
        mp.setDisplay(sw.getHolder());
        mp.prepare();
        //for testing - start
        mp.setLooping(true);
        mp.start();
        //for testing - stop

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

主な活動では、私はこれを使用しています:

        FrameLayout container = (FrameLayout)findViewById(R.id.PictureContainerLayout);
    CycleVideo v = new CycleVideo("[path to video file in assets]", this, container);
    v.prepare();

しかし、アプリケーションを起動しているとき、アクティビティのフレーム レイアウトはまだ空です。また、Eclipse の LogCat にもエラーはありません。私はどこで間違いを犯しましたか?

4

2 に答える 2

1

あなたの SurfaceView は空です。 SurfaceView とホルダーの使用については、 http ://blog.wisecells.com/2012/06/04/surface-view-android/ を参照 してください。

于 2013-07-29T14:37:28.543 に答える
0

への呼び出しを取り除きgetApplicationContext()ます。ActivityオーバーライドするContextため、必要ありません。

SurfaceView sw = new SurfaceView(activity);
于 2013-07-29T14:31:15.333 に答える