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,

相关内容

热门资讯

攻略讲解,德扑之星辅助作弊挂,... 攻略讲解,德扑之星辅助作弊挂,AApoker开挂破解窍要(本来真的有辅助器)AI 是一款可以让一直输...
总算明白!,wepoker透视... 总算明白!,wepoker透视辅助挂有游戏亮点,菠萝智星德州是如何开挂的窍门(先前存在有透视)AI ...
攻略讲解,wepoker辅助器... 攻略讲解,wepoker辅助器免费下载,菠萝智星德州究竟有没有挂窍要(起初真的有辅助器)是一款可以让...
分享给玩家,wepoker作弊... 您好:wepoker作弊软件是不是真的这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会...
重大通报,德州辅助nzt有用吗... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...
攻略讲解,wepoker线上发... 您好:wepoker线上发牌的规律这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现...
每日必备,wepoker线上发... 每日必备,wepoker线上发牌的规律,德扑之星到底有挂吗指南书(先前是真的有开挂)是一款可以让一直...
玩家必看科普!,微扑克辅助器有... 您好,微扑克辅助器有用吗这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家...
查到实测,WePoKer有没有... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...
实用技巧,德扑之星能不能透视,... 实用技巧,德扑之星能不能透视,WOK有没有透视挂举措(往昔是有透视挂)是一款可以让一直输的玩家,快速...