2013-04-20 88 views
0

我试图得到一个简单的观点基于应用程序来播放视频,但它崩溃,我的继承人的代码,iPhone应用程序崩溃,当试图播放视频

- (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

尝试这样,

NSString *audio=[[NSBundle mainBundle]pathForResource:@"1" ofType:@"mov"]; 
    NSURL *url=[[NSURL alloc]initFileURLWithPath:audio]; 
0

试试这个像,在那里你会找到我使用的代码播放电影或视频。

http://kiranjasvanee.wordpress.com/2013/09/19/play-video-or-movie-in-iphone/?preview=true&preview_id=3&preview_nonce=cf5d01de8d

让我在这里实现这个代码,因此可以对其进行审核,

首先你要导入的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]; 
     } 
    } 

}