Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 拾取视频并播放时出现的问题_Iphone_Ios_Mpmovieplayercontroller - Fatal编程技术网

Iphone 拾取视频并播放时出现的问题

Iphone 拾取视频并播放时出现的问题,iphone,ios,mpmovieplayercontroller,Iphone,Ios,Mpmovieplayercontroller,我正在尝试从lib播放视频,但我不知道我做错了什么我已经尝试了很多事情,它没有显示任何类型的错误我的代码如下 - (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info { NSString *mediaType = [info objectForKey: UIImagePickerControllerMe

我正在尝试从lib播放视频,但我不知道我做错了什么我已经尝试了很多事情,它没有显示任何类型的错误我的代码如下

- (void) imagePickerController: (UIImagePickerController *) picker
 didFinishPickingMediaWithInfo: (NSDictionary *) info {

    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

    NSURL *url = [[NSURL alloc]initWithString:mediaType];

    NSLog(@"%@",url);

    [self dismissModalViewControllerAnimated:NO];


    /* Create a new movie player object. */
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];

    if (player)
    {
               /* Specify the URL that points to the movie file. */
        [player setContentURL:url];





        /* Add a background view as a subview to hide our other view controls
         underneath during movie playback. */


        CGRect viewInsetRect = CGRectInset ([self.view bounds],
                                            kMovieViewOffsetX,
                                            kMovieViewOffsetY );
        /* Inset the movie frame in the parent view frame. */
        [[player view] setFrame:viewInsetRect];

        [player view].backgroundColor = [UIColor lightGrayColor];

        /* To present a movie in your application, incorporate the view contained
         in a movie player’s view property into your application’s view hierarchy.
         Be sure to size the frame correctly. */
        [self.view addSubview: [player view]];


        [player setCurrentPlaybackRate:0.5];
        [player play];
    }







        // Register for the playback finished notification
        [[NSNotificationCenter defaultCenter]
         addObserver: self
         selector: @selector(myMovieFinishedCallback:)
         name: MPMoviePlayerPlaybackDidFinishNotification
         object: player];



}



// When the movie is done, release the controller.
-(void) myMovieFinishedCallback: (NSNotification*) aNotification
{
    MPMoviePlayerController *playerr = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:playerr];
    [playerr stop];
    [self.view removeFromSuperview];
    [playerr autorelease];
}
首先显示的是
presetModelViewController
,然后我可以显示我库中的视频,我可以选择其中一个,但当我选择视频时,它会显示我的灰色视图,而没有显示其他内容,并且我的视频不会播放


如果您能在我的代码中找到任何错误,并能帮助我解决这些问题,那么这将是一个很大的帮助。

请浏览下面的链接,它将帮助您解决现有问题和实现


他们正在使用MPMoviePlayerViewController,这对我没有帮助,因为我想使用mpmoviecontroller的属性,比如减慢视频速度,播放视频是速度和所有其他属性这就是为什么我需要使用这种方法让我试试我会告诉你发生了什么好的蜘蛛侠任何其他建议我已经做了我的评论作为答案并在上面进行了编辑尝试使用这一点,别忘了检查,“cRect ViewInsertRect=cRecrectInset([self.view bounds],kmoviewoffsetx,kmoviewoffsety);“这是返回什么?你能发送NSString*mediaType的日志吗?让我向你展示一下它打印的是public.movie我想这就是问题所在。它应该是lib的整个url
 NSURL *videoURL = [NSURL URLWithString:videoURLString]; 
 MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]   
 initWithContentURL:videoURL]; 
 [moviePlayer prepareToPlay]; 
  [moviePlayer play]; 
  [self.view addSubview:moviePlayer.view];
This is what solved my problem thanks to spider1983 

   - (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker {

        [self dismissModalViewControllerAnimated: YES];
    }

    // For responding to the user accepting a newly-captured picture or movie
    - (void) imagePickerController: (UIImagePickerController *) picker
     didFinishPickingMediaWithInfo: (NSDictionary *) info {

        NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];


        [self dismissModalViewControllerAnimated:NO];

        // Handle a movie capture
        if (CFStringCompare ((__bridge_retained CFStringRef)mediaType, kUTTypeMovie, 0)
            == kCFCompareEqualTo) {

            NSString *moviePath = [[info objectForKey:
                                    UIImagePickerControllerMediaURL] path];




            NSLog(@"%@",[info objectForKey:
                         UIImagePickerControllerMediaURL]);


        /* Create a new movie player object. */




            MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[info objectForKey:UIImagePickerControllerMediaURL]];



        if (player)
        {
                   /* Specify the URL that points to the movie file. */
            [player setContentURL:[info objectForKey:
                                   UIImagePickerControllerMediaURL]];


            CGRect viewInsetRect = CGRectInset ([self.view bounds],
                                                kMovieViewOffsetX,
                                                kMovieViewOffsetY );
            /* Inset the movie frame in the parent view frame. */
            [[player view] setFrame:viewInsetRect];

            [player view].backgroundColor = [UIColor lightGrayColor];

            /* To present a movie in your application, incorporate the view contained
             in a movie player’s view property into your application’s view hierarchy.
             Be sure to size the frame correctly. */
            [self.view addSubview: [player view]];



            [player prepareToPlay];
            [player setCurrentPlaybackRate:0.5];
            [player play];
        }







            // Register for the playback finished notification
            [[NSNotificationCenter defaultCenter]
             addObserver: self
             selector: @selector(myMovieFinishedCallback:)
             name: MPMoviePlayerPlaybackDidFinishNotification
             object: player];
        }


    }