我正在尝试创建一个在播放不同视频后显示唯一信息页面的应用程序。目前,我正在使用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];
}