Embedded vimeo video in iPhone app using iOS 6 not playing

前端 未结 2 881
太阳男子
太阳男子 2021-02-06 16:46

I can\'t seem to get any videos playing in iOS 6. Both on the device (iP4) and simulator.

What I have is a UIWebView setup in IB. Then in my viewDidLoad I h

相关标签:
2条回答
  • 2021-02-06 17:15

    You can still use UIWebview by registering to notifications from UIMoviePlayerController and handling the corresponding events...

    -(void)viewDidLoad
    {
    
    ...
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoStarted:)   name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
    }
    
    -(void)videoStarted:(NSNotification *)notification{
    // your code here
    }
    
    -(void)videoFinished:(NSNotification *)notification{
    // your code here
    }
    
    0 讨论(0)
  • 2021-02-06 17:22

    For this I had to ditch the UIWebView completely.

    I don't know if you get this on free vimeo accounts, but on our PRO account, in the video settings there's a tab for 'video file' and at the bottom there's a field labelled 'HTTP Live Streaming' and there's practically a direct link to your video.

    And then instead of the UIWebView, I used MPMoviePlayerViewController to play the video.

    Add the MediaPlayer.framework into your 'Link Binary With Libraries' setting. In the .h file of my view controller that has a UIImageView, a couple of labels, and a play button, I imported #import <MediaPlayer/MediaPlayer.h> and setup a property @property(nonatomic, readonly) MPMoviePlayerViewController *player;

    Then, in the .m file:

    -(IBAction)playVideo:(id)sender{
        NSString *videoString = @"http://player.vimeo.com/external/THE_VIDEO_ID.m3u8?p=standard,mobile&s=UNIQUE_VALUE_FOR_EACH_VIDEO";
        player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoString]];
        [player.moviePlayer prepareToPlay];
        [player.view setFrame: self.view.bounds];
        [self.view addSubview: player.view];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
        [player.moviePlayer play];
    }
    
    - (void)MPMoviePlayerDidExitFullscreen:(NSNotification *)notification{
        [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:nil];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
        [player.moviePlayer stop];
        [player.moviePlayer.view removeFromSuperview];
    }
    

    I did try loading the HTTP Live Stream URL into the UIWebView, but it doesn't seem to work. A black screen briefly appears with the vimeo play button in the middle. Then within a second of that the fullscreen player opens for about a second, closes and then the UIWebView goes white.

    I'm still testing around with this and so far have managed to play our longest video, 1hr 45min without issue over WiFi on iOS 6 and 5.1. But hopefully this will help others out as a start.

    0 讨论(0)
提交回复
热议问题