1

我正在尝试创建一个在播放不同视频后显示唯一信息页面的应用程序。目前,我正在使用moviePlayBackDidFinish通知方法显示信息页面,但我不知道如何为不同的视频自定义它。这是我的代码...提前非常感谢!!

子类化movieplayercontroller后编辑...我如何使用新属性NSNotification

//子类movieplayercontroller myMovie.h

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

@interface myMovie: MPMoviePlayerViewController
{
    myMovie *videoPlayer;
}

@property (nonatomic, strong) NSString *movieTitle;

@end

我的电影.m

#import "myMovie.h"

@interface myMovie ()

@end

@implementation myMovie

@synthesize movieTitle;

@end

//主视图控制器

videoPlayViewController.h

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "View2.h"
#import "myMovie.h"

@interface videoPlayViewController : UIViewController


-(IBAction) playMovie;

视频播放视图控制器.m

#import "videoPlayViewController.h"
#import "myMovie.h"

@interface videoPlayViewController ()

@end


@implementation videoPlayViewController


-(void)playMovie
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
                                         pathForResource:@"sample" ofType:@"mov"]];

   myMovie *videoPlayer =  [[myMovie alloc]
                    initWithContentURL:url];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:videoPlayer.moviePlayer];




   videoPlayer.moviePlayer.controlStyle = MPMovieControlStyleDefault;
    videoPlayer.moviePlayer.shouldAutoplay = NO;
    videoPlayer.movieTitle = @"sample";
    [self.view addSubview:videoPlayer.view];
    [videoPlayer.moviePlayer setFullscreen:YES animated:YES];



}

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

    NSLog(@"Is this working?");

    View2 *second =[[View2 alloc] initWithNibName:nil bundle:nil];

    [self presentModalViewController:second animated:YES];

    [player.view removeFromSuperview];

}
4

1 回答 1

1

创建一个 MPMoviePlayerController 的子类,其中包含一个属性(或多个属性)来保存视频结束时所需的信息。然后,当视频结束时,您将在通知对象中获得自定义的 MPMoviePlayerController,并且您可以检查属性以找出您想知道的关于结束的电影的任何内容。

于 2012-08-03T23:13:36.217 回答