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,

相关内容

热门资讯

发现玩家!广丰中至510k辅助... 发现玩家!广丰中至510k辅助,决战卡五星辅助,详细技巧(揭秘有挂)1、起透看视 广丰中至510k辅...
必备辅助推荐!湖南赣湘互娱辅助... 必备辅助推荐!湖南赣湘互娱辅助,老友广东辅助工具,详细器(有挂技巧)1、老友广东辅助工具辅助器安装包...
实测交流!家乡大贰辅助,土豪联... 实测交流!家乡大贰辅助,土豪联盟怎么开辅助,详细app(有挂透明挂)运土豪联盟怎么开辅助辅助工具,进...
重大消息!九天大厅挂价格,拱趴... 重大消息!九天大厅挂价格,拱趴大菠萝系统规律,详细教程(有挂方略)拱趴大菠萝系统规律辅助器是一种具有...
教程辅助!多乐保皇辅助,福建兄... 教程辅助!多乐保皇辅助,福建兄弟13水插件,详细器(有挂教程)1、进入到福建兄弟13水插件是否有挂之...
玩家必看!丽水都莱脚本,家乡大... 玩家必看!丽水都莱脚本,家乡大贰辅助,详细插件(发现有挂)丽水都莱脚本脚本下载中分为三种模型:丽水都...
热门推荐!边锋干瞪眼ios辅助... 热门推荐!边锋干瞪眼ios辅助微信,微信链接透视脚本下载,详细工具(今日头条)运微信链接透视脚本下载...
六分钟了解!天天微友辅助器,微... 六分钟了解!天天微友辅助器,微信雀神挂件开挂辅助,详细工具(讲解有挂)1、进入到微信雀神挂件开挂辅助...
我来教大家!雀友圈斗地主有挂,... 我来教大家!雀友圈斗地主有挂,科乐辅助工作室,详细挂(有挂方式)1、任何雀友圈斗地主有挂透视是真的假...
玩家必备教程!福建天庭啊开心辅... 玩家必备教程!福建天庭啊开心辅助软件,开心泉州小程序辅助下载,详细工具(有挂总结)1、开心泉州小程序...