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,

相关内容

热门资讯

玩家必看攻略“德州wepoke... >>您好:德州wepoker透视挂确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别好,...
玩家必用“WPK免费挂机辅助器... >>您好:WPK免费挂机辅助器软件加扣扣群确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌...
最新研发“wepoker到底有... 无需打开直接搜索;操作使用教程:最新研发“wepoker到底有透视软件吗”开挂辅助下载(透视)安装教...
终于清楚“wpk德州辅助”开挂... 您好:wpk德州辅助的软件,软件加客服确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别...
揭秘“wpk透视app有哪些”... 揭秘“wpk透视app有哪些”开挂辅助工具(透视)教你攻略是一款可以让一直输的玩家,快速成为一个“必...
揭秘“wepoker原来有挂”... 您好:wepoker原来有挂这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用...
一分钟揭秘“wepoker透视... >>>您好:,软件加微信【添加136704302】确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
记者爆料“wepoker辅助挂... 无需打开直接搜索加微信客服(136704302)咨询了解wepoker辅助挂有没有辅助器目前(微信:...
来一盘“wepoker开挂辅助... >>>您好:,软件加微信【添加136704302】确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
今日百科“wepoker开挂辅... 今日百科“wepoker开挂辅助教程”开挂辅助软件(透视)可靠教程是一款可以让一直输的玩家,快速成为...