2013-04-20 120 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]; 
     } 
    } 

}