相关疑难解决方法(0)

如何从UIWebView嵌入式YouTube视频播放中接收NSNotifications

我没有收到任何通知MPMoviePlayerController.我究竟做错了什么?

我使用以下逻辑.

我开始播放youtube视频了UIWebView.UIWebView称之为标准MPMoviePlayerController.我不控制MPMoviePlayerController因为我没有实例化MPMoviePlayerController.

我使用自动播放运行youtube的剪辑(延迟1秒):

[self performSelector:@selector(touchInView:) withObject:b afterDelay:1];
Run Code Online (Sandbox Code Playgroud)

我的代码是:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];

    [self embedYouTube];
}

- (void)loadStateDidChange:(NSNotification*)notification
{
    NSLog(@"________loadStateDidChange");
}

- (void)playbackDidFinish:(NSNotification*)notification
{
    NSLog(@"________DidExitFullscreenNotification");
}

- (void)embedYouTube
{
    CGRect frame = CGRectMake(25, 89, 161, 121);
    NSString *urlString = [NSString stringWithString:@"http://www.youtube.com/watch?v=sh29Pm1Rrc0"];

    NSString *embedHTML = @"<html><head>\
    <body style=\"margin:0\">\
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>"; …
Run Code Online (Sandbox Code Playgroud)

youtube mpmovieplayercontroller mpmovieplayer nsnotificationcenter ios

51
推荐指数
5
解决办法
4万
查看次数

在UIWebView视频播放期间允许UIInterfaceOrientationLandscape

我的iPhone应用程序是一个纵向导向的应用程序,在我的应用程序中,我有UITableView一个UIWebView在第一个UITableCell.该UIWebView节目嵌入YouTube视频.当我点击视频播放时,它进入全屏模式.我需要做的是,允许用户旋转他们的设备并以横向模式播放视频.然后,当视频停止时,只允许再次使用肖像.我设置为在视频进入全屏并且全屏显示时收听通知.但我不知道如何以编程方式允许用户旋转界面方向.

所以我通常在传递通知时调用了2个方法

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];

-(void)youTubeStarted:(NSNotification *)notification{
    // Entered fullscreen code goes here.
}

-(void)youTubeFinished:(NSNotification *)notification{
    // Left fullscreen code goes here.
}
Run Code Online (Sandbox Code Playgroud)

我会在这两种方法中放置什么来仅在视频播放期间改变方向?

iphone objective-c uiwebview

10
推荐指数
1
解决办法
5433
查看次数

如何让YouTube自动播放在UIWebView中工作?

平台:iOS 6.1.Xcode 4.6.

我正在使用YouTube Javascript API和UIWebView.我可以手动点击视频缩略图,开始播放就好了.但是,自动播放不起作用.我正在为许多人建议的Web视图设置mediaPlaybackRequiresUserAction = NO.没运气.

这是代码:

@interface VideoPlayerController : UIViewController <UIWebViewDelegate>
    @property(strong, nonatomic) IBOutlet UIWebView* webView;
@end

- (void) viewDidLoad
{
    [super viewDidLoad];    

    self.webView.delegate = self;

    NSString *template = [NSString stringWithContentsOfFile:
                       [[NSBundle mainBundle]
                        pathForResource:@"YouTubeTemplate" ofType:@"txt"]];
    NSString *htmlStr = [NSString stringWithFormat: template,
        200, 200,
        @"3G4exdlsRkY"];
    self.webView.mediaPlaybackRequiresUserAction = NO;
    [self.webView loadHTMLString:htmlStr baseURL:nil];
}

- (void) webViewDidFinishLoad:(UIWebView *)wv {
    self.webView.mediaPlaybackRequiresUserAction = NO;
}
Run Code Online (Sandbox Code Playgroud)

YouTubeTemplate.txt文件是:

<html>
<head>
<script src="https://www.youtube.com/player_api"></script>
<style>
body, div {
    margin: 0px;
    padding: 0px;
}
</style>
</head>
<body> …
Run Code Online (Sandbox Code Playgroud)

youtube-javascript-api ios6

2
推荐指数
1
解决办法
7596
查看次数