Last active
July 1, 2017 08:27
-
-
Save AlaaZarifa/f81bacbebc97e6addde40c034213e808 to your computer and use it in GitHub Desktop.
video player full screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.annotation.TargetApi; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.os.Build; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.view.Window; | |
import android.widget.VideoView; | |
import com.devbrackets.android.exomedia.listener.VideoControlsVisibilityListener; | |
import com.devbrackets.android.exomedia.ui.widget.VideoControls; | |
public class FullScreenVideoPlayerActivity extends AppCompatActivity{ | |
private FullScreenListener fullScreenListener = new FullScreenListener(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
initUiFlags(); | |
/* I had to comment that since it won't resovle "getVideoControls()" | |
// if (videoView.getVideoControls() != null) { | |
// videoView.getVideoControls().setVisibilityListener(new ControlsVisibilityListener()); | |
// } | |
} | |
@Override | |
protected 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(); // I had to comment this as well, it won't resolve showControls method | |
} | |
} | |
} | |
private class ControlsVisibilityListener implements VideoControlsVisibilityListener { | |
@Override | |
public void onControlsShown() { | |
// No additional functionality performed | |
} | |
@Override | |
public void onControlsHidden() { | |
goFullscreen(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment