OGeek|极客世界-中国程序员成长平台

标题: ios - 下载时播放 Mp4 和 Mp3 文件 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:23
标题: ios - 下载时播放 Mp4 和 Mp3 文件

我想播放音频和视频文件,但我没有这些文件的 URL。我现在正在使用 AFNetwork 下载文件,文件数据是字节形式的。

[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) 
{
     float val = (float)totalBytesRead / totalBytesExpectedToRead;
     if(!isStart && val >= 0.5)
     {
        isStart = YES;

        UIWindow *window = [UIApplication sharedApplication].keyWindow;

        window = [[UIApplication sharedApplication].windows objectAtIndex:0];
            UIWebView * webView = [[UIWebView alloc]initWithFrame:window.frame];
            NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]];

            [webView loadRequest:urlRequest];
            [window addSubview:webView];
       }
}];

但是 UIWebView 没有打开这个文件我也使用了 MPMoviePlayer 但没有任何反应。 请告诉我这是否可能是部分下载的文件。



Best Answer-推荐答案


您可以使用 MPMoviePlayerController 流播放电影:

NSURL *fileURL = [NSURL URLWithString"http://www.website.com/video.mp4"];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController play];
[self.view addSubview:_moviePlayerController.view];

关于ios - 下载时播放 Mp4 和 Mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17524757/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4