0

我想知道是否有办法暂停媒体播放器并保持屏幕可见。我的意思是在暂停时将当前图像保留在屏幕上。我所做的是设置一个计时器,将媒体播放器暂停一段时间。由于当时暂停,我希望当前视频可见。但是,每次我暂停 Mediaplayer 时,屏幕都会变黑,直到我再次调用 Mediplayer.start()。有没有办法解决。

谢谢

用代码编辑

public class FullImageActivity extends Activity implements SurfaceHolder.Callback, OnPreparedListener, OnErrorListener{

private static final String TAG = null;
MediaPlayer player;
SurfaceView surfaceview;
SurfaceHolder surfaceHolder;
int width;
int height;
String path;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.full_image);

    Intent i = getIntent();

    long id = i.getExtras().getLong("id");
    path = i.getExtras().getString("videopath");

    surfaceview = (SurfaceView)findViewById(R.id.surfaceview);
    surfaceHolder = surfaceview.getHolder();
    surfaceHolder.addCallback(this);

    player = new MediaPlayer();
    playVideo();


}

public void playVideo(){
    try {
        player.reset();


        player.setOnErrorListener(this);
        player.setDataSource(path);
        player.setOnPreparedListener(this);

        player.prepareAsync();


    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}
@Override
protected void onPause() {
        player.release();
        Log.i(TAG, "Mediaplayer was relased");
    super.onPause();
}
@Override
protected void onResume() {
    playVideo();
    super.onResume();
}
@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

}
@Override
public void surfaceCreated(SurfaceHolder holder) {
    player.setDisplay(holder);
}

@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

}
@Override
public void onPrepared(MediaPlayer p) {
    width=player.getVideoWidth();
    height=player.getVideoHeight();

    if (width!=0 && height!=0) {
        surfaceHolder.setFixedSize(width, height);
        player.start();
        player.pause();
        Timer timer = new Timer();
        timer.schedule(new TimerTask()
        {
            public void run()
            {
                player.start();
            }
        }, 3000);
    }
}
4

0 回答 0