0

我正在尝试获取一个简单的基于视图的应用程序来播放视频,但是它崩溃了,这是我的代码,

 - (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]));
}
 }
4

2 回答 2

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];
        }
    }

}
于 2013-11-29T09:00:00.943 回答
0

试试这样

NSString *audio=[[NSBundle mainBundle]pathForResource:@"1" ofType:@"mov"];
    NSURL *url=[[NSURL alloc]initFileURLWithPath:audio];
于 2013-04-20T09:20:14.833 回答