在电影开始播放之前取消它

发布于 2024-09-13 12:13:01 字数 1009 浏览 5 评论 0 原文

我正在将视频流式传输到 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江南月 2024-09-20 12:13:01

我讨厌回答我自己的问题,但由于这个问题只有 7 个观点,我想它不可能那么重要。也许我不应该在半夜发布它们……当你发布时没有人看到它们。

无论如何,我没有找到解决这个问题的好方法......只是一个黑客。

在取消方法中,我告诉 moviePlayer 加载另一部第二部电影,该电影与我在预览图像中使用的照片相同。当该“电影”结束时,它会继续调用 MPMoviePlayerPlaybackDidFinishNotification 并进行清理并将用户返回到原来的位置。

-(void)cancelMovie
{
cancelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"cancel" ofType:@"m4v"]];

[theMovie setContentURL:cancelURL];

[theMovie setControlStyle:MPMovieControlStyleFullscreen];
[theMovie setFullscreen:YES];

// for some reason ... this is neccessary
[theMovie prepareToPlay];

// Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayerLoadStateChanged:) 
                                             name:MPMoviePlayerLoadStateDidChangeNotification 
                                           object:theMovie];

// Register for the PlayBackDidFinish (movie is finished)
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayBackDidFinish:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:theMovie];    
 }

不好……但它有效。

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.

-(void)cancelMovie
{
cancelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"cancel" ofType:@"m4v"]];

[theMovie setContentURL:cancelURL];

[theMovie setControlStyle:MPMovieControlStyleFullscreen];
[theMovie setFullscreen:YES];

// for some reason ... this is neccessary
[theMovie prepareToPlay];

// Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayerLoadStateChanged:) 
                                             name:MPMoviePlayerLoadStateDidChangeNotification 
                                           object:theMovie];

// Register for the PlayBackDidFinish (movie is finished)
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayBackDidFinish:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:theMovie];    
 }

Not good... but it works.

把梦留给海 2024-09-20 12:13:01

@Michael 解决方案有效。
可以改进的是无需播放取消视频。相反,您可以直接调用 MPMoviePlayerPlaybackDidFinishNotification

[self moviePlayBackDidFinish:nil];

首先我实现了@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.

[self moviePlayBackDidFinish:nil];

First i implemented @Michael's idea, but eventually, i succeeded without playing next video.

安人多梦 2024-09-20 12:13:01
-(void)cancelMovie
{
    if (_mediaPlayer){
        [_mediaPlayer stop];
        _mediaPlayer.initialPlaybackTime = -1.0;
        _mediaPlayer.contentURL = nil;
        [_mediaPlayer prepareToPlay];
    }
}
-(void)cancelMovie
{
    if (_mediaPlayer){
        [_mediaPlayer stop];
        _mediaPlayer.initialPlaybackTime = -1.0;
        _mediaPlayer.contentURL = nil;
        [_mediaPlayer prepareToPlay];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文