【问题标题】:YTPlayerView - Autorotation support to YTPlayerViewYTPlayerView - 对 YTPlayerView 的自动旋转支持
【发布时间】:2014-10-12 12:37:43
【问题描述】:

我正在使用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"];
}
-----
-----
}

我不能使用这个检查来提供更大的尺寸来查看,因为上面的代码没有调用中间视频播放。

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

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

【问题讨论】:

    标签: ios objective-c uiwebview ytplayerview


    【解决方案1】:

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

    这是css示例:

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

    【讨论】:

      【解决方案2】:

      我在故事板中使用了 YTPlayer,并且在我的项目中使用了自动布局时对其进行了适当的限制。它在横向和纵向模式下对我来说都很好。我认为你的问题的解决方案是自动布局

      【讨论】:

        猜你喜欢
        • 2014-06-14
        • 2014-10-17
        • 1970-01-01
        • 2016-12-22
        • 2014-10-04
        • 2014-11-10
        • 2015-10-14
        • 2019-01-03
        • 2017-05-23
        相关资源
        最近更新 更多