0

'MoviePlayerController'のサブクラスが何を意味するのか理解できません。a)これは、新しいView Controllerを作成し、それにMPMoviePlayerControllerインスタンスを追加するときですか?b)他に何かありますか?いくつかのコード例は非常に役立ちます。

ありがとう

4

2 に答える 2

3

非常に多くの文字を使用するため、これは上記のコメントにはなりません。

OK @ 1110 UITapGestureRecognizerをプレーヤービューに追加することを想定します。これは、フルスクリーンのピンチジェスチャ/フルスクリーンの削除をすでにサポートしていることを忘れないでください。以下のコードは、MPMoviePlayerControllerをiVarとして使用するViewControllerを使用していることを前提としています。

プレーヤーのコントローラーを表示/非表示にするためにタップ検出カウント1がすでに使用されているため、シングルタップを検出したくない場合があります。

以下は、ダブルタップ用のジェスチャレコグナイザーを使用したコード例です。

PlayerViewController.hのコード

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

@interface PlayerViewController : UIViewController {}

//iVar
@property (nonatomic, retain) MPMoviePlayerController *player;

// methods
- (void)didDetectDoubleTap:(UITapGestureRecognizer *)tap;
@end

PlayerViewController.mのコード

#import "PlayerViewController.h"

@implementation PlayerViewController
@synthesize player;

- (void)dealloc
{
    [player release];
    [super dealloc];
}

- (void)viewDidLoad
{

    // initialize an instance of MPMoviePlayerController and set it to the iVar
    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://path/to/video.whatever"]];
    // the frame is the size of the video on the view
    mp.view.frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height / 2);
    self.player = mp;
    [mp release];
    [self.view addSubview:self.player.view];
    [self.player prepareToPlay];

    // add tap gesture recognizer to the player.view property
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didDetectDoubleTap:)];
    tapGesture.numberOfTapsRequired = 2;
    [self.player.view addGestureRecognizer:tapGesture];
    [tapGesture release];

    // tell the movie to play
    [self.player play];

    [super viewDidLoad];
}

- (void)didDetectDoubleTap:(UITapGestureRecognizer *)tap {
    // do whatever you want to do here
    NSLog(@"double tap detected");
}

@end

参考までに、私はこのコードをチェックアウトしました、そしてそれは動作します。

于 2011-07-11T15:47:45.907 に答える
2

サブクラス化の意味がわからない場合は、「継承」というトピックを調査する必要があります。特にiOSの主題をカバーする多くの資料があるはずです。特に、Xcodeでファイルを作成するとき、おそらくすでにクラスをサブクラス化しています。ほとんどの場合、ビューなどを作成するときにNSObjectまたはUIViewControllerをサブクラス化します。

MPMoviePlayerControllerはストリーミング用に構築された非常に高度なクラスであるため、サブクラス化することはおそらく望ましくありません。MPMoviePlayerViewControllerは、通常のView Controllerと同じように機能しますが、iVarとしてMPMoviePlayerControllerがすでに付属しています。

以下の要約宣言:

@interface MPMoviePlayerViewController : UIViewController {}
@property(nonatomic, readonly) MPMoviePlayerController *moviePlayer;
@end

サンプルコードは、次のAppleドキュメントセンターにあります。

https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingVideo/UsingVideo.html#//apple_ref/doc/uid/TP40009767-CH3-SW1

ここにあるムービープレーヤーXcodeプロジェクト:

https://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007798

iOSデバイスから映画を再生するのは本当に簡単です。Appleのドキュメントですべてを読んでください。これらのクラスのヘッダーファイルを確認すると、何を扱っているかについての洞察も得られます。

お役に立てば幸いです。

于 2011-07-09T19:50:08.110 に答える