在 iPhone 上从 url 播放一个视频时调用另一个 URL
在我的应用程序中,我正在依次播放数组中的 2 个视频。我想在第一个视频开始播放时点击另一个网址,而不影响视频播放。
这是我尝试依次播放两个视频的代码,
-(IBAction)playMovie:(id)sender{
i=0;
array=[[NSArray alloc] initWithObjects:@"https://s3.amazonaws.com/adplayer/colgate.mp4",@"https://s3.amazonaws.com/ventuno-platform-flv-sep2010/happy_family.mp4",nil];
[self initializPlayer]; }
当用户单击按钮开始播放视频时,将调用上述操作事件。
-(void)initializPlayer{
if(i<[array count])
i +=1;
else {
i = 1;
}
NSLog(@"i value:%@",[array objectAtIndex:i-1]);
NSURL *url1=[NSURL URLWithString:[array objectAtIndex:i-1]];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url1];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerPlaybackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen=YES;
[moviePlayerController play];}
在initializPlayer方法中,两个视频依次播放,并且有两个通知,第一个用于通知视频播放完毕或用户按下完成按钮。另一个用于通知,
1.videoplay 2.视频暂停 3.视频中断 4.视频转发 5.videobackward
-(void)moviePlaybackComplete:(NSNotification *)notification{
NSLog(@"moviePlaybackComplete");
MPMoviePlayerController *moviePlayerController=[notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
[self initializPlayer];}
moviePlaybackComplete通知用于在视频播放完成时通知用户。
-(void) moviePlayerPlaybackStateDidChange:(NSNotification*)notification {
NSLog(@"moviePlayerPlaybackStateDidChange");
MPMoviePlayerController *moviePlayer = notification.object;
MPMoviePlaybackState playbackState = moviePlayer.playbackState;
if(playbackState == MPMoviePlaybackStateStopped)
{
//NSLog(@"MPMoviePlaybackStateStopped");
}
if(playbackState == MPMoviePlaybackStatePlaying)
{
//NSLog(@"MPMoviePlaybackStatePlaying");
}
if(playbackState == MPMoviePlaybackStatePaused)
{
//NSLog(@"MPMoviePlaybackStatePaused");
}
if(playbackState == MPMoviePlaybackStateInterrupted)
{
NSLog(@"MPMoviePlaybackStateInterrupted");
}
if(playbackState == MPMoviePlaybackStateSeekingForward)
{
NSLog(@"MPMoviePlaybackStateSeekingForward");
}
if(playbackState == MPMoviePlaybackStateSeekingBackward)
{
NSLog(@"MPMoviePlaybackStateSeekingBackward********");
}}
moviePlayerPlaybackStateDidChange 通知用于通知用户播放状态是否发生任何更改。
我的疑问:
在第一个视频播放(开始)时,我想在不影响视频的情况下点击另一个网址。在第一个视频的末尾再点击一个网址。
请指导我这样做。
谢谢
In my application i'm playing 2 videos from array one after another.I want to hit another url at the time of first video begin to play without affecting the video playing.
Here is my code what i have tried for playing two videos one after another,
-(IBAction)playMovie:(id)sender{
i=0;
array=[[NSArray alloc] initWithObjects:@"https://s3.amazonaws.com/adplayer/colgate.mp4",@"https://s3.amazonaws.com/ventuno-platform-flv-sep2010/happy_family.mp4",nil];
[self initializPlayer]; }
The above action event is called when user click on the button to start playing the videos.
-(void)initializPlayer{
if(i<[array count])
i +=1;
else {
i = 1;
}
NSLog(@"i value:%@",[array objectAtIndex:i-1]);
NSURL *url1=[NSURL URLWithString:[array objectAtIndex:i-1]];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url1];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerPlaybackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen=YES;
[moviePlayerController play];}
In initializPlayer method two videos are playing one after another, and also two notifications are there,first one is used to notify when the video completed or user press the done button.another one is used to notify,
1.videoplay
2.videopause
3.video Interrupted
4.videoforward
5.videobackward
-(void)moviePlaybackComplete:(NSNotification *)notification{
NSLog(@"moviePlaybackComplete");
MPMoviePlayerController *moviePlayerController=[notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
[self initializPlayer];}
moviePlaybackComplete notification is used to notify the user when the video is completed.
-(void) moviePlayerPlaybackStateDidChange:(NSNotification*)notification {
NSLog(@"moviePlayerPlaybackStateDidChange");
MPMoviePlayerController *moviePlayer = notification.object;
MPMoviePlaybackState playbackState = moviePlayer.playbackState;
if(playbackState == MPMoviePlaybackStateStopped)
{
//NSLog(@"MPMoviePlaybackStateStopped");
}
if(playbackState == MPMoviePlaybackStatePlaying)
{
//NSLog(@"MPMoviePlaybackStatePlaying");
}
if(playbackState == MPMoviePlaybackStatePaused)
{
//NSLog(@"MPMoviePlaybackStatePaused");
}
if(playbackState == MPMoviePlaybackStateInterrupted)
{
NSLog(@"MPMoviePlaybackStateInterrupted");
}
if(playbackState == MPMoviePlaybackStateSeekingForward)
{
NSLog(@"MPMoviePlaybackStateSeekingForward");
}
if(playbackState == MPMoviePlaybackStateSeekingBackward)
{
NSLog(@"MPMoviePlaybackStateSeekingBackward********");
}}
moviePlayerPlaybackStateDidChange notification is used to notify the user if any changes is made in playbackstate.
MY DOUBT:
At the time of first video playing(beginning) i want to hit another url without affecting the video.Hit one more url at the end of the first video.
Please Guide me to do this.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论