mil*_*eph 9 youtube api android orientation
使用YouTubeBaseActivity,YouTubePlayerView和YouTubePlayer启动并运行示例活动非常简单.虽然方向有问题,但找不到任何文档或示例代码.当我在播放视频时切换屏幕是空白的.
在onCreate(),onPause(),onSaveInstanceState()和onRestoreInstanceState()中,要使视频继续播放,有哪些正确的操作?
谢谢
The*_*ist 25
变量
@SuppressLint("InlinedApi")
private static final int PORTRAIT_ORIENTATION = Build.VERSION.SDK_INT < 9
? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
@SuppressLint("InlinedApi")
private static final int LANDSCAPE_ORIENTATION = Build.VERSION.SDK_INT < 9
? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
private YouTubePlayer mPlayer = null;
private boolean mAutoRotation = false;
Run Code Online (Sandbox Code Playgroud)
在OnCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAutoRotation = Settings.System.getInt(getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION, 0) == 1;
}
Run Code Online (Sandbox Code Playgroud)
实现OnInitializedListener
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
mPlayer = player;
player.setOnFullscreenListener(this);
if (mAutoRotation) {
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION
| YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI
| YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE
| YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
} else {
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION
| YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI
| YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
}
}
Run Code Online (Sandbox Code Playgroud)
补充onConfigurationChanged
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (mPlayer != null)
mPlayer.setFullscreen(true);
}
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
if (mPlayer != null)
mPlayer.setFullscreen(false);
}
}
@Override
public void onFullscreen(boolean fullsize) {
if (fullsize) {
setRequestedOrientation(LANDSCAPE_ORIENTATION);
} else {
setRequestedOrientation(PORTRAIT_ORIENTATION);
}
}
Run Code Online (Sandbox Code Playgroud)
Menifest
<activity
android:name="com.sample.android.YouTubePlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="sensor"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
</activity>
Run Code Online (Sandbox Code Playgroud)
我做了一个使用最新的youtube api的示例活动.
此源处理" 方向问题 "," 媒体卷问题 "," Youtube Url解析问题 "
这是示例应用程序的git项目
我还制作了可以下载的示例应用程序
https://play.google.com/store/apps/details?id=com.thefinestartist.ytpa.sample
| 归档时间: |
|
| 查看次数: |
6246 次 |
| 最近记录: |