ios - YTPlayerView - 对 YTPlayerView 的自动旋转支持

标签 ios objective-c uiwebview ytplayerview

我正在使用 YTPlayerView 类来播放 YouTube 视频。下面是我用来根据设备屏幕尺寸(iPad 的大尺寸和 iPhone 的小尺寸)加载视频的代码。它工作正常。

问题 -- 当我将设备模式更改为横向时,我想要更大的 YTPlayerView 然后是纵向模式。目前,两种屏幕模式下的视频大小相同。

- (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams {
NSDictionary *playerCallbacks = @{
                                  @"onReady" : @"onReady",
                                  @"onStateChange" : @"onStateChange",
                                  @"onPlaybackQualityChange" : @"onPlaybackQualityChange",
                                  @"onError" : @"onPlayerError"
                                  };
NSMutableDictionary *playerParams = [[NSMutableDictionary alloc] init];
[playerParams addEntriesFromDictionary:additionalPlayerParams];

if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
    [playerParams setValue:@"551px" forKey:@"height"];
    [playerParams setValue:@"768px" forKey:@"width"];
}
else
{
    [playerParams setValue:@"250px" forKey:@"height"];
    [playerParams setValue:@"320px" forKey:@"width"];
}
-----
-----
}

我不能使用此检查来提供更大的 View ,因为上面的代码不会调用中间视频播放。

if([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscape)

你们知道如何解决这个问题吗?或者如果有任何其他解决方案使用 JavaScript 和 css 作为 webView 的 html 字符串。

最佳答案

YTPlayerView其实是用webview来播放viedo的,所以只能用css或者javascript来改变大小。 Assets 文件夹中应该有一个名为“YTPlayerView-iframe-player.html”的 html 文件。

这是 CSS 示例:

<style>
    body { margin: 0; width:100%%; height:100%%; }
    html { width:100%%; height:100%%; }
</style>

关于ios - YTPlayerView - 对 YTPlayerView 的自动旋转支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25382952/

相关文章:

ios - 频率分析 - Novocaine 和麦克风播放 : how to disable speaker output?

iphone - 从 super View 中删除后保持图像在 View 中

ios - 如何使用EGOCache更快地缓存和加载页面

iphone - 设备方向更改时 UIWebview 中出现黑条

iphone - 为 MapKit 转换 "world file"GIS?

ios - 按照用户方向旋转 collectionView

objective-c - 您应该如何处理 NSStream 阻塞的可能性?

objective-c - 如何为 Game Center 挑战在 uint64_t 上存储结构信息

iphone - 将 UIWebView 适配到 UITableViewCell

ios - 在 UIButton 背景图像顶部添加渐变层