簡體   English   中英

MPMoviePlayer在應用程序中不起作用

[英]MPMoviePlayer doesn't work in app

我正在嘗試用我的視頻創建一個應用,以便在帶有UIButton的視圖中播放。 僅供參考:我正在使用帶有標簽欄視圖控制器的情節提要,因此此代碼MPMoviePlayerView在另一個視圖內。

我不斷收到此錯誤: *由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:'* -[NSURL initFileURLWithPath:]:無字符串參數'

這是我的代碼:

VideoTefViewController.h

#import <UIKit/UIKit.h>

@interface VideoTefViewController : UIViewController


-(IBAction)playMovie;
@end

VideoTefViewController.m

#import "VideoTefViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface VideoTefViewController ()

@end

@implementation VideoTefViewController

-(IBAction)playMovie {

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"tef" ofType:@"mp4"];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie play];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

錯誤告訴您fileURLWithPath:的參數為nil,因此出於某種原因moviePath為nil。 您確定捆綁包中有一個名為tef.mp4的文件嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM