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,

相关内容

热门资讯

此事迅速冲上热搜!德州机器人代... 此事迅速冲上热搜!德州机器人代打脚本(透视)遇悦游戏辅助(确实有辅助修改器)-哔哩哔哩1、每一步都需...
透视实锤!德州透视是真的假的(... 透视实锤!德州透视是真的假的(透视)亿游十三道辅助(果然存在有辅助下载)-哔哩哔哩;该软件可以轻松地...
随着!wepoker私人局规律... 随着!wepoker私人局规律(透视)蜀山四川小程序作必弊码大全(原来是真的辅助修改器)-哔哩哔哩1...
截至目前!wpk是真的还是假的... 截至目前!wpk是真的还是假的(透视)潮汕汇木虱辅助下载(竟然是有辅助软件)-哔哩哔哩1、潮汕汇木虱...
在玩家背景下!wepoker黑... 在玩家背景下!wepoker黑侠辅助器正版下载(透视)开心泉州辅助(其实是有辅助app)-哔哩哔哩1...
透视中牌率!哈糖大菠萝怎么开挂... 透视中牌率!哈糖大菠萝怎么开挂(透视)打两圈辅助软件(好像真的有辅助下载)-哔哩哔哩1、哈糖大菠萝怎...
透视科技!约局吧德州可以透视吗... 透视科技!约局吧德州可以透视吗(透视)人海大厅软件辅助(切实真的有辅助修改器)-哔哩哔哩1)人海大厅...
最终!we poker游戏下(... 最终!we poker游戏下(透视)聚友联盟免费辅助器(好像真的是有辅助app)-哔哩哔哩1、该软件...
备受关注的!wepokerpl... 备受关注的!wepokerplus开挂(透视)浙江宝宝游戏透视辅助器(原来是真的辅助工具)-哔哩哔哩...
事发当天!德州局怎么透视(透视... 事发当天!德州局怎么透视(透视)透视辅助器免费蜀山四川(竟然真的有辅助神器)-哔哩哔哩透视辅助器免费...