2012-01-24 9 views
0

これで、前回のコードを正しく投稿できませんでした...私は初心者です。私は少し変更して、私はuiTableViewから再生するビデオを取得しようとしています。私はクラッシュすることはありません、私はちょうど約20秒間黒い画面を取得し、シミュレータまたはiPhoneは、uiTableViewに戻ります。 「オプション1」を選択すると、警告が表示されます。私は、iOS 4.0用に開発したXcode 4.2を使用しています。まだ私のアプリでビデオを再生しようとしています

私は2,3日間頭を叩いていて、何か助けに感謝しています。

はここに私の.h

#import <UIKit/UIKit.h> 
#import <MediaPlayer/MediaPlayer.h> 

@interface faq2 : UITableViewController 
{ 
    NSArray *faqList; 
} 
@property (nonatomic, strong) NSArray *faqList; 
-(IBAction)playMovie; 
@end 

であることはここで私は私がproplerlyフレームワークを追加しましたかなり確信している私の.m

-(IBAction)playMovie 
{ 
    NSString *filepath = [[NSBundle mainBundle] pathForResource:@"WhatFinalTake" ofType:@"mp4"]; 
    NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlaybackComplete:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:moviePlayerController]; 

    [self.view addSubview:moviePlayerController.view]; 
    moviePlayerController.fullscreen = YES; 
    [moviePlayerController play]; 
} 

- (void)moviePlaybackComplete:(NSNotification *)notification 
{ 
    MPMoviePlayerController *moviePlayerController = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:moviePlayerController]; 

    [moviePlayerController.view removeFromSuperview]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    self.faqList = [[NSArray alloc] initWithObjects: 
        @"Play Movie", 
        @"Option 1", nil]; 

    self.title = @"Frequently Asked Questions"; 
} 

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

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return [faqList count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    // Configure the cell. 
    cell.textLabel.text = [self.faqList objectAtIndex: [indexPath row]]; 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row == 0) 
    { 
     [self playMovie]; 
    } 
    else if (indexPath.row == 1) 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Option 1" message:@"Option 1" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil, nil]; 
     [alert show]; 
    } 
} 

ですが、JIKはここにスクリーンショットです。 enter image description here

+0

ログにエラーメッセージがありますか? –

+0

は20秒ほどのビデオですか?黒い画面が実際にあなたのビデオである可能性があります –

+0

私のログを確認する方法はわかりません。私のビデオは約2分です。ログでエラーをチェックするにはどうすればよいですか? – sdknewbie

答えて

1

コードをテストしたところ、filePath文字列がnilであることが判明しました。試してみてください:

NSString *filepath = [NSString stringWithFormat:@"%@",[[NSBundle mainBundle] pathForResource:@"WhatFinalTake" ofType:@"mp4"]]; 
NSLog(@"%@",filepath); 
NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
+0

Hmm。私はXcodeが初めてです。私はターゲットを選択し、 "ファイルを追加..."ビデオファイルは、画面の左側にある私の.mファイルの真上にあります。私はそれを置くべき特定のフォルダがありますか?映画がコードによって見つからないように聞こえる。 – sdknewbie

+0

ファイルがあなたのプロジェクトに存在しない限り、filePathはnilと思われます。 –

+0

私はアプリを再構築し、 "Use Automatic Reference Counting"の選択を解除し、ビデオの再生を開始しました。ロギングについてのヒントをありがとう。それが必要な時にプレイヤーがそこにいなかった理由を見つけ出すことに私は気づいた。私は "ARC"は私が望むほどスマートではないと思う。 – sdknewbie

0

"WhatFinalTake.mp4"ファイルをプロジェクトに追加しましたか?

私はビデオの再生に役立つ以下、あなたはのtableViewからこれを呼び出すことができますが見つかりました:

http://iosdevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html

私は(iOSのバージョンによって異なります)、LoadStateChanged通知またはPreloadDidFinishに登録すると便利です見つけてみませんかそこからの実際の演劇はビデオが準備されていることを確かめる。上記のリンクからこれを行う方法を見つけることができます。彼はあなたのためにそれをすべて行ったので、私は単に提供されたコードを使用することをお勧めします。

関連する問題