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,

相关内容

热门资讯

透视智能ai"wep... 透视智能ai"wepoker破解游戏盒子"详细辅助必备教程(俱乐部辅助透视)准备好在wepoker破...
透视代打"wepok... 透视代打"wepoker怎么拿到好牌"详细辅助透视教程(透视底牌方法);《WPK辅助透视》‌:支持手...
透视神器"来玩app... 透视神器"来玩app破解"详细辅助德州论坛(破解是真的还是假的神器);最新版2024是一款经典耐玩的...
透视真的"拱趴游戏破... 这是一款非常优秀的拱趴游戏破解器 ia辅助检测软件,能够让你了解到拱趴游戏破解器中牌率当中全部隐藏参...
透视脚本"约局吧辅助... 自定义约局吧辅助器系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不管你是...
透视app"wejo... 1、透视app"wejoker辅助脚本"详细辅助wpk教程(靠谱技巧)(UU poker、wejok...
透视辅助"wepok... 透视辅助"wepoker辅助器"详细辅助介绍教程(破解游戏盒子技巧)1、许多玩家不知道wepoker...
透视透视"hhpok... 透视透视"hhpoker有没有作弊辅助"详细辅助必赢方法(安装透视软件攻略)1、许多玩家不知道hhp...
透视透视"aapok... 透视透视"aapoker透视方法"详细辅助细节方法(免费脚本透视);小薇(透视辅助)致您一封信;亲爱...
透视能赢"wepok... 透视能赢"wepoker怎么开辅助"详细辅助辅助教程(可以发冤家牌软件);wepoker怎么开辅助软...