Xcode iPhone应用程序在尝试播放视频时崩溃
我正在尝试使用一个简单的基于视图的应用程序来播放视频,但它崩溃了,下面是我的代码Xcode iPhone应用程序在尝试播放视频时崩溃,xcode,video,Xcode,Video,我正在尝试使用一个简单的基于视图的应用程序来播放视频,但它崩溃了,下面是我的代码 - (IBAction)playButton:(id)sender { NSString *stringPath = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"mov"]; NSURL *url = [NSURL fileURLWithPath:stringPath]; mpc = [[MPMoviePlayerControl
- (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]));
}
}
//
//main.m
//视频播放
//
//由nathaniel harman于2013年4月20日创建。
//版权所有(c)2013 machupicchumobile。版权所有。
//
#进口
#导入“VideoPlayAppDelegate.h”
int main(int argc,char*argv[])
{
@自动释放池{
返回UIApplicationMain(argc、argv、nil、NSStringFromClass([VideoPlayAppDelegate类]);
}
}
像这样试试
NSString *audio=[[NSBundle mainBundle]pathForResource:@"1" ofType:@"mov"];
NSURL *url=[[NSURL alloc]initFileURLWithPath:audio];
试着这样做,你会发现我用来播放电影或视频的代码 让我在这里实现这段代码,这样我们可以查看它 首先,您必须导入MediaPlayer标题库,以使用其MPMoviePlayer播放任何电影或视频。 您可以在.h或.m视图控制器中导入此库–具体取决于您在何处声明MPMoviePlayerViewController对象 库导入:-
#import MediaPlayer/MediaPlayer.h
对象声明:-
MPMoviePlayerViewController *moviePlayer;
按下播放电影时,在.m文件中实现以下代码:-
下面使用的电影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];
}
}
}