我正在将视频流式传输到 iPhone,但不喜欢 MPMoviePlayerController 一开始处理事情的方式。我注意到,当您单击该行以选择特定电影时,该应用程序只会坐在那里,直到它加载到足以播放它为止。因此,我弹出了一个 UIImageView,其中包含加载图像和一个漂亮的旋转器,以让用户了解情况。
我认为如果他们厌倦了等待,他们应该可以选择取消电影的播放。所以我有一个带有背景图像的取消按钮。
UIButton *cancel;
UIImage *cancelImage = [UIImage imageNamed:@"cancel.png"];
cancel = [UIButton buttonWithType:UIButtonTypeCustom];
cancel.frame = CGRectMake(0,0, cancelImage.size.width, cancelImage.size.height);
cancel.center = CGPointMake(35, 20);
[cancel setImage:cancelImage forState:UIControlStateNormal];
[cancel addTarget:self action:@selector(cancelMovie) forControlEvents:UIControlEventTouchUpInside];
[moviePreviewView addSubview:cancel];
但我不确定在 cancelMovie 方法中放入什么。我尝试复制 moviePlayBackDidFinish 回调方法中的内容,但它崩溃得相当惊人。
我也尝试过:
-(void)cancelMovie {
[theMovie.view removeFromSuperview];
[theMovie release];
}
但这也没有什么好处。我想我可以直接调用 moviePlayBackDidFinish 但我不认为你可以直接调用通知方法。
你的想法?
I'm streaming video to the iPhone and don't like the way MPMoviePlayerController handles things at the beginning. I noticed that when you click on the row to select a particular movie the app just sits there until it is loaded sufficiently to play it. So I popped in a UIImageView with a loading image and a nice spinner to keep the user informed.
I think they should have the option to cancel the play back of the movie if they get tired of waiting. So I've got a cancel button with a background image.
UIButton *cancel;
UIImage *cancelImage = [UIImage imageNamed:@"cancel.png"];
cancel = [UIButton buttonWithType:UIButtonTypeCustom];
cancel.frame = CGRectMake(0,0, cancelImage.size.width, cancelImage.size.height);
cancel.center = CGPointMake(35, 20);
[cancel setImage:cancelImage forState:UIControlStateNormal];
[cancel addTarget:self action:@selector(cancelMovie) forControlEvents:UIControlEventTouchUpInside];
[moviePreviewView addSubview:cancel];
But I'm not sure what to put in the cancelMovie method. I've tried duplicating what I have in the moviePlayBackDidFinish call back method but it crashes rather spectacularly.
I also tried:
-(void)cancelMovie {
[theMovie.view removeFromSuperview];
[theMovie release];
}
But that doesn't do anything good either. I was thinking I could call the moviePlayBackDidFinish directly but I don't think you can call a notification method directly.
Your thoughts?
发布评论
评论(3)
我讨厌回答我自己的问题,但由于这个问题只有 7 个观点,我想它不可能那么重要。也许我不应该在半夜发布它们……当你发布时没有人看到它们。
无论如何,我没有找到解决这个问题的好方法......只是一个黑客。
在取消方法中,我告诉 moviePlayer 加载另一部第二部电影,该电影与我在预览图像中使用的照片相同。当该“电影”结束时,它会继续调用 MPMoviePlayerPlaybackDidFinishNotification 并进行清理并将用户返回到原来的位置。
不好……但它有效。
I hate answering my own question but since this question only had 7 views it couldn't be that important I suppose. Perhaps I shouldn't post them in the middle of the night... no one sees them when you do.
Anyway, I didn't find a good solution to this problem... just a hack.
In the cancel method I told the moviePlayer to load a different, one second movie that is a the same photo I used in the previewImage. When that 'movie' finishes it then proceeds to call the MPMoviePlayerPlaybackDidFinishNotification and cleans up and returns the user back where they were.
Not good... but it works.
@Michael 解决方案有效。
可以改进的是无需播放取消视频。相反,您可以直接调用 MPMoviePlayerPlaybackDidFinishNotification。
首先我实现了@Michael的想法,但最终我成功了,没有播放下一个视频。
@Michael solution works.
There could be improvement that there is no need to play cancel video. Instead, you can directly call the MPMoviePlayerPlaybackDidFinishNotification directly.
First i implemented @Michael's idea, but eventually, i succeeded without playing next video.