我正在尝试使用一个简单的基于视图的应用来播放视频,但它会崩溃,继承我的代码,
- (IBAction)playButton:(id)sender {
NSString *stringPath = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"mov"];
NSURL *url = [NSURL fileURLWithPath:stringPath];
mpc = [[MPMoviePlayerController alloc]initWithContentURL:url];
[mpc setMovieSourceType:MPMovieSourceTypeFile];
[[self view]addSubview:mpc.view];
[mpc setFullscreen:YES];
[mpc play];
}
@end
这就是xcode失败时我需要的地方
//
// main.m
// video_play
//
// Created by nathaniel harman on 20/04/2013.
// Copyright (c) 2013 machupicchumobile. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "VideoPlayAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([VideoPlayAppDelegate class]));
}
}
答案 0 :(得分:0)
尝试这样,
NSString *audio=[[NSBundle mainBundle]pathForResource:@"1" ofType:@"mov"];
NSURL *url=[[NSURL alloc]initFileURLWithPath:audio];
答案 1 :(得分:0)
试试这个,在那里你会找到我用来播放电影或视频的代码。
让我在这里实现这个代码,所以可以查看它,
首先,您必须导入MediaPlayer标头库才能使用它的MPMoviePlayer播放任何电影或视频。 您可以在.h或.m视图控制器中导入此库 - 取决于您声明MPMoviePlayerViewController对象的位置。
图书馆导入: -
#import MediaPlayer/MediaPlayer.h
对象声明: -
MPMoviePlayerViewController *moviePlayer;
在.m文件中实现以下代码,当按下播放电影时: - 下面使用的Movie_URL标识符包含视频或电影的URL。
- (IBAction)BtnVideoShowCalled:(id)sender
{
// Put your Navigation and Tabbar related code here.
Ex :- /* self.navigationController.navigationBarHidden=YES; */
//If you wanna play a video from tableview, then assign tag to _btn and add target this function to that _btn. Ex :-
/*
//Where, record is a object of Messages class.
NSInteger tid = [sender tag];
*/
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",Movie_URL]];
if(URL)
{
Class mplayerControllerClass = NSClassFromString(@"MPMoviePlayerViewController");
if(mplayerControllerClass != nil) {
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:URL];
moviePlayer.wantsFullScreenLayout = YES;
[moviePlayer shouldAutorotateToInterfaceOrientation:YES];
if(moviePlayer)
{
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
[movieplayer readyPlayer];
}
}
}