如何在ExoMedia Library中显示视频控件

时间:2017-08-03 05:39:44

标签: android android-studio github exoplayer

我正在使用ExoMedia Library在我的Android应用程序中播放hls。 但我无法像搜索按钮那样显示视频控件,它只显示播放按钮而不显示任何其他内容。当我尝试使用EMVideoView时,应用程序崩溃了。我正在使用Android Studio Canary 4。 这是代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.devbrackets.android.exomedia.ui.widget.VideoView
    android:id="@+id/video_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:useDefaultControls="true"/>
</RelativeLayout>

如果我使用EMVideoView而不是VideoView,那么应用程序崩溃。

 public class ExternalPlayer extends AppCompatActivity implements 
  OnPreparedListener {

private FullScreenListener fullScreenListener = new FullScreenListener();
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_external_player);
    setupVideoView();
    initUiFlags();
    if (videoView.getVideoControls() != null) {
        videoView.getVideoControls().setVisibilityListener(new ControlsVisibilityListener());
    }
}

private void setupVideoView() {
    // Make sure to use the correct VideoView import
    Intent intent = getIntent();
    String link = intent.getStringExtra("url");
    videoView = (VideoView)findViewById(R.id.video_view);
    videoView.setOnPreparedListener(ExternalPlayer.this);
    videoView.showControls();
    //Uri coming from MOMScreen to play
    videoView.setVideoURI(Uri.parse(link));
}

@Override
public void onPrepared() {
    videoView.start();
}



@Override
public void onDestroy() {
    super.onDestroy();
    exitFullscreen();
}

private void goFullscreen() {
    setUiFlags(true);
}

private void exitFullscreen() {
    setUiFlags(false);
}

private void initUiFlags() {
    int flags = View.SYSTEM_UI_FLAG_VISIBLE;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
    }

    View decorView = getWindow().getDecorView();
    if (decorView != null) {
        decorView.setSystemUiVisibility(flags);
        decorView.setOnSystemUiVisibilityChangeListener(fullScreenListener);
    }
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setUiFlags(boolean fullscreen) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        View decorView = getWindow().getDecorView();
        if (decorView != null) {
            decorView.setSystemUiVisibility(fullscreen ? getFullscreenUiFlags() : View.SYSTEM_UI_FLAG_VISIBLE);
        }
    }
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private int getFullscreenUiFlags() {
    int flags = View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    }

    return flags;
}

private class FullScreenListener implements View.OnSystemUiVisibilityChangeListener {
    @Override
    public void onSystemUiVisibilityChange(int visibility) {
        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
            videoView.showControls();

        }
    }
}


private class ControlsVisibilityListener implements VideoControlsVisibilityListener {
    @Override
    public void onControlsShown() {
        // No additional functionality performed

    }

    @Override
    public void onControlsHidden() {
        goFullscreen();
    }
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

}

我已经尝试了所有方法来显示控件,据我所知,但没有一个工作。 任何建议请....

1 个答案:

答案 0 :(得分:0)

我也面临同样的问题。然后在下面的存储库的帮助下修复它。如果你是其他人,你也可以参考它。它可能对你有帮助。

https://github.com/brianwernick/ExoMedia

视频控件在以下链接中说明。 https://devbrackets.com/dev/libs/docs/exomedia/3.1.0/com/devbrackets/android/exomedia/ui/widget/VideoControls.html#setNextButtonEnabled-boolean-

更具体地说是setNextButtonEnabled()和setNextButtonRemoved()