Thursday, September 26, 2013

Play Video from remote URL in UIWebView and MPMoviePlayerViewController ----- IOS

/***************************playVideoInWebView Start********************/
- (void)playVideoInWebView
{
 NSString *embedHTML = @"\
    <html><head>\
    <style type=\"text/css\">\
    body {\
    background-color: transparent;\
    color: white;\
    }\
    </style>\
    </head><body style=\"margin:0\">\
    <embed id=\"yt\" src=\"YOUR----URL--HERE \" type=\"application/x-shockwave-mp4\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>";
  
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height)];
  
    [self.webView setOpaque:NO];

    NSString *html = [NSString stringWithFormat:embedHTML, self.webView.frame.size.width, self.webView.frame.size.height];

    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"YOUR_URL_HERE"]]];

    [self.webView scalesPageToFit];

    webView.delegate = self;
  
    [self.view addSubview:webView];
 

}

/***************************playVideoInWebView End********************/



/***************************playVideoInMoviePlayer Start********************/

- (void)playVideoInPlayer
{
   moviePlayerController_ = [[MPMoviePlayerViewController alloc] init];
     url = [NSURL URLWithString:@"https://testvideo.fidelity.tv/asset/l6yo1b8uYfv.mp4?format=mobile_mp4"]; 
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:nil];
   
    self.moviePlayerController_.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    [self.moviePlayerController_.moviePlayer setContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:self.moviePlayerController_];
   
}


- (void)moviePlaybackDidFinish:(NSNotification*)noti{

    NSLog(@"finish..%@",[noti userInfo]);
 
}

/***************************playVideoInMoviePlayer End********************/

No comments:

Post a Comment