Android YouTube api v3– 方向

Android YouTube api v3– 方向,第1张

概述使用YouTubeBaseActivity,YouTubePlayerView和YouTubePlayer启动并运行示例活动非常简单.虽然方向有问题,但找不到任何文档或示例代码.当我在播放视频时切换屏幕是空白的.在onCreate(),onPause(),onSaveInstanceState()和onRestoreInstanceState()中,要使视频继续播放,有哪些正确

使用YouTubeBaseActivity,YouTubePlayerVIEw和YouTubePlayer启动并运行示例活动非常简单.虽然方向有问题,但找不到任何文档或示例代码.当我在播放视频时切换屏幕是空白的.

在onCreate(),onPause(),onSaveInstanceState()和onRestoreInstanceState()中,要使视频继续播放,有哪些正确的 *** 作?

谢谢

解决方法:

变量

@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;

在OnCreate

@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    mautoRotation = Settings.System.getInt(getContentResolver(),            Settings.System.ACCELEROMETER_ROTATION, 0) == 1;}

实现OnInitializedListener

@OverrIDepublic 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);    }}

补充onConfigurationChanged

@OverrIDepublic 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);    }}@OverrIDepublic voID onFullscreen(boolean fullsize) {    if (fullsize) {        setRequestedOrIEntation(LANDSCAPE_ORIENTATION);    } else {        setRequestedOrIEntation(PORTRAIT_ORIENTATION);    }}

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>

我已经使用最新的youtube API进行了示例活动.

此源处理“方向问题”,“媒体卷问题”,“Youtube Url解析问题”

>这是样本应用程序的git项目

https://github.com/TheFinestArtist/YouTubePlayerActivity
>我还制作了可以下载的示例应用程序

https://play.google.com/store/apps/details?id=com.thefinestartist.ytpa.sample

总结

以上是内存溢出为你收集整理的Android YouTube api v3 – 方向全部内容,希望文章能够帮你解决Android YouTube api v3 – 方向所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100533.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存