视频无法在IOS中播放 [英] Video not playing in IOS

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

问题描述

我正在下载这样的视频.

I am downloading a video like this..

-(IBAction)buttonPress:(id)sender{

  movieURL = [NSURL URLWithString:@"https://www.dropbox.com/s/Screen%20Capture2013-01-31%2014_21_22.mov"];

    NSURLRequest *theRequest = [NSURLRequest requestWithURL:movieURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];

    if( connection )
    {
         receivedData = [[NSMutableData alloc] initWithLength:0];
    }
    else
    {
        //[delegate ConnectionFailed];
    }
}



- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [receivedData setLength:0];
}

- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [receivedData appendData:data];
    NSLog(@"dee- %@",receivedData);
}

- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
  //  [connection release];
}

- (NSCachedURLResponse *) connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
    return nil;
}

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
   // [connection release];
    [self movieReceived];
}

但是我无法播放此视频.请帮助我保存并播放此视频.

But I am not able to play this video. Please help me to save and play this video.

我已经尝试过了,但是没有用.\

i have tried this but doesnt work.\

-(void)movieReceived{
MPMoviePlayerViewController* tmpMoviePlayViewController=[[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];

    if (tmpMoviePlayViewController) {

        tmpMoviePlayViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

        [self presentViewController:tmpMoviePlayViewController animated:YES completion:nil];

        tmpMoviePlayViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

        [[NSNotificationCenter defaultCenter] addObserver:self

                                                 selector:@selector(myMovieViewFinishedCallback:)

                                                     name:MPMoviePlayerPlaybackDidFinishNotification

                                                   object:tmpMoviePlayViewController];

        [tmpMoviePlayViewController.moviePlayer play];


}
}

推荐答案

使用以下代码

-(void)movieReceived{
{
       NSString *strVideoUrl = @"abc.com/xyz" // your VideoUrl in String
       strVideoUrl = [strVideoUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
       NSURL *url = [NSURL URLWithString:strVideoUrl];
       moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];

       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDonePressed:) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];

       moviePlayer.controlStyle=MPMovieControlStyleDefault;
       //moviePlayer.shouldAutoplay=NO;
       [moviePlayer play];
       [self.view addSubview:moviePlayer.view];
       [moviePlayer setFullscreen:YES animated:YES];
}

- (void) moviePlayBackDonePressed:(NSNotification*)notification
{
       [moviePlayer stop];
       [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];


       if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)])
       {
              [moviePlayer.view removeFromSuperview];
       }
       moviePlayer=nil;
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
      [moviePlayer stop];
      [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];

     if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)])
     {
          [moviePlayer.view removeFromSuperview];
     }
}

像这样使用您的问题将解决~~~~~祝您好运~~~~~~

use like this your problem will solve ~~~~~Best Of Luck ~~~~~~

这篇关于视频无法在IOS中播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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