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,

相关内容

热门资讯

4分钟脚本!福建大玩家透视,雀... 4分钟脚本!福建大玩家透视,雀友会广东潮汕苹果(本来真的是有辅助工具)-哔哩哔哩;1、雀友会广东潮汕...
6分钟安装!大菠萝挂机辅助,四... 6分钟安装!大菠萝挂机辅助,四川家园辅助器(都是真的有辅助平台)-哔哩哔哩1、玩家可以在四川家园辅助...
第六分钟插件!欢乐情怀脚本辅助... 第六分钟插件!欢乐情怀脚本辅助器,奇迹陕西游戏辅助器(果然真的有辅助插件)-哔哩哔哩进入游戏-大厅左...
第七分钟安装!新超圣伏虎,开心... 第七分钟安装!新超圣伏虎,开心泉州小程序辅助哪里查看(原来真的有辅助工具)-哔哩哔哩1、用户打开应用...
5分钟安装!巴郎新疆辅助器,情... 5分钟安装!巴郎新疆辅助器,情怀宜春怎么开挂(一贯真的有辅助平台)-哔哩哔哩1、情怀宜春怎么开挂脚本...
八分钟插件!新永和源代码,钱塘... 八分钟插件!新永和源代码,钱塘十水三攻略(好像有挂辅助平台)-哔哩哔哩1、钱塘十水三攻略辅助器安装包...
十分钟辅助!yy比鸡脚本,越乡... 十分钟辅助!yy比鸡脚本,越乡游辅助工具(确实是有辅助神器)-哔哩哔哩所有人都在同一条线上,像星星一...
九分钟安装!789大菠萝可以控... 九分钟安装!789大菠萝可以控制吗,拱趴大菠萝技巧(竟然存在有辅助下载)-哔哩哔哩一、789大菠萝可...
三分钟阶段!wepoker一直... 三分钟阶段!wepoker一直输的号能继续打吗(透视)一直是真的有辅助开挂(哔哩哔哩)1、wepok...
8分钟辅助!扣点点脚本辅助器,... 8分钟辅助!扣点点脚本辅助器,蛮籽酉阳大贰辅助(一直是有辅助软件)-哔哩哔哩小薇(辅助器软件下载)致...