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,

相关内容

热门资讯

盘点一款!微信雀神麻将挂件开挂... 盘点一款!微信雀神麻将挂件开挂辅助,微乐家乡麻将自建房辅助app(开挂自建房)插件1、让任何用户在无...
重大发现!微乐自建房辅助工具挂... 重大发现!微乐自建房辅助工具挂,微乐家乡麻将自建房辅助app(开挂自建房)app1、任何微乐家乡麻将...
盘点一款!微乐自建房辅助工具神... 盘点一款!微乐自建房辅助工具神器,微乐小程序免费黑科技(开挂自建房)app;1、这是跨平台的微乐自建...
大家学习交流!微乐自建房辅助工... 大家学习交流!微乐自建房辅助工具免费app,微乐家乡麻将自建房辅助app(开挂自建房)脚本1)微乐家...
教学盘点!微信雀神麻将挂件开挂... 教学盘点!微信雀神麻将挂件开挂辅助,微乐家乡麻将自建房辅助app(开挂自建房)插件进入游戏-大厅左侧...
带你了解!微信卡五星辅助器,微... 带你了解!微信卡五星辅助器,微乐自建房脚本免费入口(开挂自建房)攻略;1、下载好微信卡五星辅助器正确...
总算了解!微乐自建房辅助工具脚... 总算了解!微乐自建房辅助工具脚本,微乐自建房脚本免费入口(开挂自建房)技巧;一、微乐自建房辅助工具脚...
玩家必备教程!微乐自建房辅助工... 玩家必备教程!微乐自建房辅助工具,微乐小程序免费黑科技(开挂自建房)器1、玩家可以在微乐自建房辅助工...
记者爆料!微信卡五星辅助器,微... 记者爆料!微信卡五星辅助器,微乐自建房脚本免费入口(开挂自建房)软件1、点击下载安装,微信卡五星辅助...
关于!微乐家乡麻将自建房辅助a... 关于!微乐家乡麻将自建房辅助app,微乐家乡麻将自建房辅助app(开挂自建房)技巧1、实时微乐家乡麻...