gpt4 book ai didi

android - 如何在配置更改时处于暂停模式时显示android媒体播放器的前一帧

转载 作者:行者123 更新时间:2023-11-29 01:18:16 28 4
gpt4 key购买 nike

现在我正在使用 android 媒体播放器。因此,当用户将屏幕从纵向旋转到横向,反之亦然时,媒体播放器出现问题。

用户在某个帧以纵向模式暂停视频,因此当用户旋转屏幕时,我想在暂停的地方显示相同的屏幕。在这种情况下,我可以保存玩家之前的位置并向后退,但在这里我看到的是黑屏,而不是上一帧。

代码:1

//Here i am saving previous position of mediplayer
protected void onSaveInstanceState(Bundle outState) {

outState.putLong(KEY_IS_MAIN_VIDEO_CURRENT_POSITION, mMainVideoMediaPlayer.getCurrentPosition());

super.onSaveInstanceState(outState);
}

2.获取之前的值

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.videoplay_new_layout);

if (savedInstanceState != null) {
mIsConfigChanged = true;


mMainVideoPreviousPosition = savedInstanceState.getLong(KEY_IS_MAIN_VIDEO_CURRENT_POSITION);


}

3.准备调用时将保存的先前值设置回播放器

mMainVideoMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {

mMainVideoMediaPlayer.start();
//Setting previous value::::

mMainVideoMediaPlayer.seekTo((int) mMainVideoPreviousPosition);

//Making player pause because mediaplayer player previous state is paused in potrait mode:::

mMainVideoMediaPlayer.pause();


}
});

最佳答案

如果您尝试过评论部分,请尝试这个并告诉我。

mMainVideoMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {

mMainVideoMediaPlayer.start();


mMainVideoMediaPlayer.seekTo((int) mMainVideoPreviousPosition);

//Making player pause because mediaplayer player previous state is paused in potrait mode:::

mMainVideoMediaPlayer.pause();

//Try this code below like hack for now.
//---------------
<playButton>.pefromClick(); //It will start playing
<pauseButton>.perfromClick(); //immediately pause it.
//------------------


}
});

关于android - 如何在配置更改时处于暂停模式时显示android媒体播放器的前一帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38370632/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com