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,

相关内容

热门资讯

总算明白!!德普软件,wepo... 『标题:当前标题』主打赛后复盘的 AI 游戏攻略黑科技走红,对局总结能力开挂。上传对局回放或者战绩截...
大神讲解!德普之星透视软件免费... 德普之星透视软件免费入口官网AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载对应游戏...
玩家必看科普!!wpk辅助软件... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...
玩家必看教程!!wpk透视是真... 玩家必看教程!!wpk透视是真的假的,微扑克有挂吗插件(真是真的有开挂)主打本地运行的 AI 黑科技...
必备科技!wpk有没有脚本,w... 『标题:当前标题』主打赛后复盘的 AI 游戏攻略黑科技走红,对局总结能力开挂。上传对局回放或者战绩截...
大家学习交流!wepoker透... 大家学习交流!wepoker透视底牌脚本,wepoker开挂透视教程下载(素来是有辅助器)主打本地运...
推荐一款!wpk透视脚本视频,... 您好:wpk透视脚本视频这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的...
技术分享!!wejoker黑侠... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...
2025版教程!wpk插件,德... 『标题:当前标题』主打赛后复盘的 AI 游戏攻略黑科技走红,对局总结能力开挂。上传对局回放或者战绩截...
让我来分享经验!wpk俱乐部辅... 让我来分享经验!wpk俱乐部辅助器,WPK有没有透视挂下载(一贯真的有辅助)主打本地运行的 AI 黑...