我用我的屏幕(桌面)捕获软件创建了.mov视频文件,我想在UIWebview中的应用程序中播放该视频。有没有办法播放该视频或任何其他方式,以便我可以为我的本地视频创建一个URL ???
I have created .mov video file with my screen(desktop) capture software and I want that video to play in my application in UIWebview. Is there any way to play that video or any other way so that I can create a URL for my local video ???
现在我使用默认视频链接用于在UIWebview中播放视频。
Right now I mm using a default video link for playing video in UIWebview.
以下是代码:
- (void)applicationDidBecomeActive:(UIApplication *)application { self.viewVideoDisplay.frame = CGRectMake(0, 0, 1024, 1024); [self.window addSubview:self.viewVideoDisplay]; [self.window bringSubviewToFront:self.viewVideoDisplay]; NSString *urlAddress = @"response.questback/pricewaterhousecoopersas/zit1rutygm/"; //Create a URL object. NSURL *url = [NSURL URLWithString:urlAddress]; //URL Requst Object NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; //Load the request in the UIWebView. [self.webViewVideo loadRequest:requestObj]; IsLoadingSelf = YES; }但我没有想要播放的视频网址..
but I dont have url of video which I want to play..
请帮助!!
推荐答案编辑: MPMoviePlayerController 现已弃用。所以我使用了 AVPlayerViewController 。并编写以下代码:
MPMoviePlayerController is Deprecated Now. So I have used AVPlayerViewController. and written the following code:
NSURL *videoURL = [NSURL fileURLWithPath:filePath]; //filePath may be from the Bundle or from the Saved file Directory, it is just the path for the video AVPlayer *player = [AVPlayer playerWithURL:videoURL]; AVPlayerViewController *playerViewController = [AVPlayerViewController new]; playerViewController.player = player; //[playerViewController.player play];//Used to Play On start [self presentViewController:playerViewController animated:YES completion:nil];请不要忘记导入以下框架:
Please do not forget to import following frameworks:
#import <AVFoundation/AVFoundation.h> #import <AVKit/AVKit.h>您可以使用 MPMoviePlayerController 播放本地文件。
You can use MPMoviePlayerController to play local file.
1。添加 Mediaplayer 框架并执行#在viewController中导入< MediaPlayer / MediaPlayer.h> 。
2。拖放视频文件您在桌面上创建了xcode。
2. Drag and drop your video file you created on desktop into the xcode.
3. 获取本地视频的路径。
3. Get the path of the local video.
NSString*thePath=[[NSBundle mainBundle] pathForResource:@"yourVideo" ofType:@"MOV"]; NSURL*theurl=[NSURL fileURLWithPath:thePath];4. 用您的路径初始化moviePlayer。
4. Initialize the moviePlayer with your path.
self.moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:theurl]; [self.moviePlayer.view setFrame:CGRectMake(40, 197, 240, 160)]; [self.moviePlayer prepareToPlay]; [self.moviePlayer setShouldAutoplay:NO]; // And other options you can look through the documentation. [self.view addSubview:self.moviePlayer.view];5. 要控制播放后要执行的操作:
5. To control what is to be done after playback:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playBackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; //playBackFinished will be your own method.编辑2 :处理 AVPlayerViewController的完成而不是 MPMoviePlayerController ,请使用以下内容...
EDIT 2: To handle completion for AVPlayerViewController rather than MPMoviePlayerController, use the following...
AVPlayerItem *playerItem = player.currentItem; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playBackFinished:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];在这个例子中,我解雇 AVPlayerViewController 完成后:
In this example, I dismiss the AVPlayerViewController after completion:
-(void)playBackFinished:(NSNotification *) notification { // Will be called when AVPlayer finishes playing playerItem [playerViewController dismissViewControllerAnimated:false completion:nil]; }更多推荐
如何播放本地视频文件?
发布评论