gpt4 book ai didi

ios - MPMoviePlayerController 视频未播放

转载 作者:行者123 更新时间:2023-12-02 17:44:30 26 4
gpt4 key购买 nike

我在我的应用程序中使用了 MPMoviePlayerController。
我获得了正确的 URL,但 MPMoviePlayer 无法播放视频,仅显示黑屏。
我的代码如下:

[video setImage:[UIImage imageNamed:@"video_active.png"] forState:UIControlStateNormal];
NSString *filename=[NSString stringWithFormat:@"%@.mp4",[appdel.TempVideoUrl valueForKey:tag]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:filename];
NSURL *movieURL = [NSURL fileURLWithPath:filePath] ;
theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.view.frame = CGRectMake(106, 18, 216, 235);
[uploadview addSubview:theMovie.view];

// Play the movie.
[theMovie pause];

我得到的网址是这样的: 文件://本地主机/var/mobile/Applications/6E1D4CB7-A08D-438B-9FE7-E2FD9B7B5EEC/Documents/136_1355227629.mp4

最佳答案

在调用[theMovie play];之前添加[theMovieprepareToPlay];

prepareToPlay

Prepares a movie player for playback. (required)

- (void)prepareToPlay

Discussion

If a movie player is not already prepared to play when you call the play method, that method automatically calls this method. However, to minimize playback delay, call this method before you call play.

Calling this method may interrupt the movie player’s audio session. For information on interruptions and how to resond to them, see Audio Session Programming Guide. Availability

Available in iOS 3.2 and later.

Declared In MPMediaPlayback.h

您还可以使用 isPreparedToPlay检查电影播放器​​是否准备好播放。

请引用此link了解更多。

关于ios - MPMoviePlayerController 视频未播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13820391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com