【问题标题】:Play Mp4 and Mp3 file while downloding下载时播放 Mp4 和 Mp3 文件
【发布时间】:2023-04-09 09:58:02
【问题描述】:

我想播放音频和视频文件,但我没有这些文件的 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 但没有任何反应。 请告诉我这是否可能是部分下载的文件。

【问题讨论】:

    标签: ios objective-c afnetworking mpmovieplayer movie


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,但我没有文件 URL,我正在使用网络服务下载文件。
    • 您有网络应用程序的源代码示例吗?您需要解析他以提取网址。
    • 我有一个用于下载文件的 Web 服务,该文件以字节形式返回正在进行的块中的文件数据。
    猜你喜欢
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多