我正在尝试创建一个在不同视频播放后显示唯一信息页面的应用。目前,我正在使用moviePlayBackDidFinish
通知方法显示信息页面,但我无法弄清楚如何为不同的视频自定义它。这是我的代码...非常感谢提前!!
继承电影播放器控制器后编辑...如何在NSNotification
中使用新属性?
//子类movieplayercontroller myMovie.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface myMovie: MPMoviePlayerViewController
{
myMovie *videoPlayer;
}
@property (nonatomic, strong) NSString *movieTitle;
@end
myMovie.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;
videoPlayViewController.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];
}
答案 0 :(得分:1)
使用属性(或许多属性)创建MPMoviePlayerController的子类,以保存视频结束时所需的信息。然后,当视频结束时,您将在通知对象中获得自定义的MPMoviePlayerController,并且您可以检查属性以找出您想要了解的有关已结束的电影的内容。