gpt4 book ai didi

iphone - 选择视频并播放时出现问题

转载 作者:行者123 更新时间:2023-11-29 03:48:11 24 4
gpt4 key购买 nike

我正在尝试从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 显示出来,然后我可以显示我的库中的视频,我可以选择其中一个,但是当我选择视频时,它会显示我的灰色 View ,没有其他内容,我的视频无法播放。

如果您能发现我的代码中的任何错误并可以帮助我解决此问题,那么这将是很大的帮助。

最佳答案

请浏览以下链接,这将帮助您解决现有问题并实现。

http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios

 NSURL *videoURL = [NSURL URLWithString:videoURLString]; 
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:videoURL];
[moviePlayer prepareToPlay];
[moviePlayer play];
[self.view addSubview:moviePlayer.view];

关于iphone - 选择视频并播放时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17424293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com