AndroidMotionLayout与ExoPlayer切换方向时的错误问题。
创始人
2024-10-09 08:33:29
0

该问题的解决方法是使用一个自定义的ExoPlayerView和一个自定义的PlayerViewGestureDetector类。

首先在布局文件中,使用MotionLayout将自定义的ExoPlayerView嵌套。

可以使用以下代码实现自定义的ExoPlayerView:

public class CustomExoPlayerView extends FrameLayout {

private SimpleExoPlayer player;
private PlayerView playerView;

public CustomExoPlayerView(@NonNull Context context) {
    super(context);
    init();
}

public CustomExoPlayerView(@NonNull Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    init();
}

public CustomExoPlayerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
}

private void init() {
    LayoutInflater.from(getContext()).inflate(R.layout.view_custom_exoplayer, this);
    playerView = findViewById(R.id.player_view);
}

public void setPlayer(SimpleExoPlayer player) {
    this.player = player;
    playerView.setPlayer(player);
}

public SimpleExoPlayer getPlayer() {
    return player;
}

public void setVideoURI(Uri uri) {
    player.prepare(new ProgressiveMediaSource.Factory(new DefaultHttpDataSourceFactory("exoplayer")).createMediaSource(uri));
}

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    if (player != null) {
        player.release();
    }
}

}

然后在自定义的ExoPlayerView中使用自定义的PlayerViewGestureDetector类来监听手势操作,如下:

public class CustomExoPlayerView extends FrameLayout {

private SimpleExoPlayer player;
private PlayerView playerView;
private PlayerViewGestureDetector playerViewGestureDetector;

public CustomExoPlayerView(@NonNull Context context) {
    super(context);
    init();
}

public CustomExoPlayerView(@NonNull Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    init();
}

public CustomExoPlayerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs,

相关内容

热门资讯

十分钟实锤!德州之星外挂(手机... 十分钟实锤!德州之星外挂(手机德州)其实真的是有挂(详细辅助新版2025教程)1、上手简单,内置详细...
第1分钟实锤!德州之星辅助挂(... 第1分钟实锤!德州之星辅助挂(线上德州)切实真的是有挂(详细辅助爆料教程);1、起透看视 德州之星辅...
第二分钟实锤!德州免费辅助神器... 第二分钟实锤!德州免费辅助神器app(德州wpk)都是是真的有挂(详细辅助安装教程)1、让任何用户在...
第十分钟实锤!德州之星外挂(手... 第十分钟实锤!德州之星外挂(手机德州)切实真的是有挂(详细辅助必胜教程)1、德州之星外挂ai辅助优化...
第6分钟实锤!德扑起手牌胜率图... 第6分钟实锤!德扑起手牌胜率图(德扑)真是有挂(详细辅助解密教程)1、进入游戏-大厅左侧-新手福利-...
3分钟实锤!德扑之星ai代打(... 3分钟实锤!德扑之星ai代打(德州wpk)总是有挂(详细辅助必胜教程);1、德扑之星ai代打机器人多...
四分钟实锤!德州免费辅助神器a... 四分钟实锤!德州免费辅助神器app(德州扑克)原来存在有挂(详细辅助科技教程)1、构建自己的德州免费...
第二分钟实锤!智星德州菠萝外挂... 第二分钟实锤!智星德州菠萝外挂(德州扑克)真是是有挂(详细辅助技巧教程)一、智星德州菠萝外挂软件透明...
第8分钟实锤!德州微扑克辅助(... 第8分钟实锤!德州微扑克辅助(德扑ai)竟然是真的有挂(详细辅助新2025教程);1、玩家可以在德州...
第7分钟实锤!德州ai人工智能... 第7分钟实锤!德州ai人工智能(德州俱乐部)本来真的有挂(详细辅助介绍教程)一、德州ai人工智能AI...