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,

相关内容

热门资讯

重大发现!微乐小程序辅助工具,... 重大发现!微乐小程序辅助工具,收i就微乐小程序游戏破解器-切实是有辅助器(有人有挂)小薇(辅助器软件...
玩家必备科普!微乐小程序游戏破... 玩家必备科普!微乐小程序游戏破解器,微乐自建房辅助软件-本来真的有辅助攻略(今日头条)1、这是跨平台...
详细说明!微信微乐小程序游戏辅... 详细说明!微信微乐小程序游戏辅助脚本,微信微乐辅助透视-好像真的是有辅助方法(有挂技巧)1、上手简单...
研究成果!微乐小程序微乐辅助软... 研究成果!微乐小程序微乐辅助软件,微信小程序微乐辅助免费版-果然真的有辅助软件(有挂规律)微乐小程序...
推荐十款!微信微乐辅助免费,微... 推荐十款!微信微乐辅助免费,微乐自建房辅助工具安全吗-好像真的有辅助教程(真的有挂)1、很好的工具软...
科技通报!微信微乐小程序有挂黑... 科技通报!微信微乐小程序有挂黑科技,微信小程序微乐辅助器ios-其实真的有辅助脚本(有挂详细)1、任...
每日必看!微乐小程序微乐辅助软... 每日必看!微乐小程序微乐辅助软件,微乐陕西小程序脚本-原来有辅助软件(有挂秘籍)1、微乐小程序微乐辅...
每日必看!微乐家乡麻将辅助,下... 每日必看!微乐家乡麻将辅助,下载微乐小程序自建房透视-其实存在有辅助攻略(有挂功能)微乐家乡麻将辅助...
热点讨论!微信微乐小程序辅助器... 热点讨论!微信微乐小程序辅助器免费安装,微乐家乡小程序自建房辅助app-都是存在有辅助工具(有挂教学...
实测教程!微信小程序微乐房间怎... 实测教程!微信小程序微乐房间怎么开挂,微信自建房辅助多少钱一个月-真是存在有辅助app(有挂秘籍)1...