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,

相关内容

热门资讯

分享给玩家!多乐游戏小程序辅助... 分享给玩家!多乐游戏小程序辅助器免费,葫芦娃辅助软件,推荐开挂辅助教程(有挂教学)1、下载安装好多乐...
教学盘点!决战十三水辅助,萍乡... 教学盘点!决战十三水辅助,萍乡滚筒四幅攻略,关于开挂辅助教程(有挂方法);无需打开直接搜索加(薇:1...
一分钟了解!微信新海贝之城辅助... 一分钟了解!微信新海贝之城辅助,友友联盟辅助免费下载,了解开挂辅助教程(有挂存在);无需打开直接搜索...
研究成果!微信边锋干橙眼辅助,... 研究成果!微信边锋干橙眼辅助,浙江宝宝游戏辅助,必看开挂辅助教程(发现有挂);无需打开直接搜索薇:1...
分享实测!榆林打锅子辅助器,微... 分享实测!榆林打锅子辅助器,微信微乐游戏辅助脚本,传授开挂辅助教程(真的有挂);无需打开直接搜索打开...
一分钟了解!闲来辅助神器怎么下... 一分钟了解!闲来辅助神器怎么下载,赣牌圈破解器,分享开挂辅助教程(有挂讲解);无需打开直接搜索打开薇...
玩家实测!微乐自建房脚本免费下... 玩家实测!微乐自建房脚本免费下载,三江互娱辅助,教会开挂辅助教程(有挂工具);无需打开直接搜索加(薇...
分享一款!广东潮汕雀友会插件,... 分享一款!广东潮汕雀友会插件,金杯竞技辅助,教会开挂辅助教程(有挂技巧);无需打开直接搜索加薇136...
每日必看!奇迹陕西游戏辅助,小... 每日必看!奇迹陕西游戏辅助,小闲川南手游辅助器,发现开挂辅助教程(有挂技术);无需打开直接搜索薇:1...
必备辅助推荐!朋友局辅助器,对... 必备辅助推荐!朋友局辅助器,对战互娱辅助,分析开挂辅助教程(有挂攻略);无需打开直接搜索打开薇:13...