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辅助技... 四分钟介绍!wepoke辅助技巧,德州之星ai辅助(详细透视辅助插件教程)wepoke辅助技巧平台为...
八分钟攻略!永州四王扯胡子包赢... 八分钟攻略!永州四王扯胡子包赢,众合推扑克辅助工具(详细透视辅助软件教程)1、这是跨平台的永州四王扯...
五分钟透明!双辽麻将有挂吗,微... 《软件透明挂》是一款多人竞技的辅助透视游戏,你将微扑克对手来到同一个战场,为至高无上的荣耀进行一次自...
we辅助poker德之星!we... we辅助poker德之星!wepoke有假吗(wepoke好友房)切实是真的有挂(详细智能ai教程)...
WePoKe透明挂!wepok... WePoKe透明挂!wepoke德州扑克系统规律(wepoke app)一直存在有挂(详细透视挂教程...
微扑克辅助挂!微扑克wpk安全... 《微扑克辅助挂软件透明挂》是一款多人竞技的微扑克辅助挂辅助透视游戏,你将微扑克对手来到同一个战场,为...
红龙扑克辅助!红龙扑克有挂吗,... 红龙扑克辅助!红龙扑克有挂吗,(红龙扑克)其实是有挂(详细辅助器教程)1、让任何用户在无需AI插件第...
红龙扑克辅助器!红龙扑克好友桌... 红龙扑克辅助器!红龙扑克好友桌,(红龙扑克)一贯真的有挂(详细辅助工具教程);原来确实真的有挂(需添...