我正在尝试从 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
是显示然后我可以显示我的库中的视频我可以选择其中一个但是当我选择视频时它显示我的灰色视图而没有其他任何内容并且我的视频没有播放。
如果你能在我的代码中发现任何错误并且可以帮助我,那么这将是很大的帮助。