以全屏自动播放 YouTube 视频 [英] Play youtube videos in fullscreen auto

查看:28
本文介绍了以全屏自动播放 YouTube 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ipad 应用程序中的 youtube 嵌入式播放器播放 youtube 视频.我希望一旦用户点击视频缩略图,视频就应该在 ipad 切换到横向模式时自动全屏加载.目前,用户必须单击全屏按钮才能以全屏模式播放视频.我想要使​​用 ipad 附带的默认 youtube 应用播放视频时看到的相同效果.

I am trying to play a youtube video using youtube embedded player in my ipad app. I want that as soon as the user clicks on the video thumbnail the video automatically should be loaded fullscreen on switching to landscape mode in ipad. Currently the user has to click the fullscreen button to play the video in fullscreen mode. I want the same effect that is seen when we play the video using the default youtube app that comes with ipad.

这是我用来在 ipad 上播放管视频的代码.

This is the code that I am using to play you tube video on ipad.

embedHTML = @"<object width="640" height="390">
<param name="movie"value="http://www.youtube.com/v/IYX_Ql-3U10&fs=1">
<param name="allowFullScreen" value="true"></param>
<param name="allowScriptAccess" value="always"></param>
<embed id="yt" src="http://www.youtube.com/v/youtube_video_id&fs=1" 
type="application/x-shockwave-flash" position="fixed" 
allowfullscreen="true" allowScriptAccess="always"
 width="640" height="390"></embed></object>";

如果这是不可能的,有人知道是否有理由或文件支持这一决定.

And if this is not possible does anybody know if there is a reason or documentation supporting this decision.

推荐答案

我能够使用 iOS youtube helper FigPluginView 的子视图访问此功能="https://github.com/youtube/youtube-ios-player-helper" rel="nofollow">iOS-youtube-player-helper.FigPluginView 类转储参考

I was able to access this functionality from a subview titled FigPluginView within the youtube player's webview, using the iOS youtube helper iOS-youtube-player-helper. FigPluginView class dump reference

创建一个自定义 UIView 类标头,公开以下方法:

Create a custom UIView class header that exposes the following method:

#import <Foundation/Foundation.h> 
@interface WMFigPluginView : NSObject

-(void)scriptEnterFullScreen;

@end

将自定义的 FigPluginView 和 YouTube 播放器导入到 ViewController 界面()

Import the custom FigPluginView and YouTube player to the ViewController interface()

    #import <youtube-ios-player-helper/YTPlayerView.h>
    #import "WMFigPluginView.h"

    @property(nonatomic, strong) YTPlayerView *playerView;

使用以下方法初始化youtube播放器,监控状态变化,在FigPluginView中查找和调​​用全屏脚本.

Use the following methods to init the youtube player, monitor state change, find and call the fullscreen script within the FigPluginView.

- (void)presentYoutubeVideo {
    if ([self.view.subviews containsObject:_playerView]){
        [_playerView removeFromSuperview];
    }
    CGRect playerFrame = CGRectMake(0, 0, 0, 0);
    _playerView = [[YTPlayerView alloc]initWithFrame:playerFrame];
    _playerView.delegate = self;
    [_playerView.webView setAllowsInlineMediaPlayback: NO];
    [self.view addSubview:_playerView];
    [self.playerView loadWithVideoId:@"YouTubeVideoID" playerVars:@{@"showinfo":@0,@"modestbranding":@1,@"autoplay":@1,@"playsinline":@0}];
}

-(void)playerViewDidBecomeReady:(YTPlayerView *)playerView {
    [_playerView playVideo];
}

-(void)playerView:(YTPlayerView *)playerView didChangeToState:(YTPlayerState)state {
    //stop activity indicator
    if (state == kYTPlayerStateBuffering) {
        //start activity indicator
    }
    if (state == kYTPlayerStatePlaying) {
        WMFigPluginView *figPluginView = (WMFigPluginView*)[self findFigPluginView:_playerView.webView];
        [figPluginView scriptEnterFullScreen];
    }
}

- (UIView *)findFigPluginView:(UIView *)view {
    for (__unsafe_unretained UIView *subview in view.subviews) {
        if ([NSStringFromClass(subview.class) hasSuffix:@"FigPluginView"]) {
            return subview;
        } else if (subview.subviews.count > 0) {
            return [self findFigPluginView:subview];
        }
    }
    return nil;
}

希望这有帮助!

这篇关于以全屏自动播放 YouTube 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆