1

我的程序(iphone 应用程序)由两部分组成 - 在不同线程上运行的服务器套接字(位于端口 3490)和用于测试服务器的客户端。服务器有一个视频文件,我想根据请求将它发送给客户端。我喜欢这样:

int fileDesc = open([viewController.filePath UTF8String], O_RDONLY);

            if (fileDesc == -1) {
                fprintf(stderr, "unable to open '%s': %s\n", [viewController.filePath UTF8String], strerror(errno));
                exit(1);
            }

            off_t offset = 0;
            off_t len = 0;
            struct sf_hdtr headers;
            headers.headers = NULL;
            headers.trailers = NULL;
            if (sendfile (fileDesc, new_fd, offset, &len, NULL, 0) == -1){
                perror("send");
            }

现在我的客户这样称呼:

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://127.0.0.1:3490/"]];
    [moviePlayer play];

现在是奇怪的部分。在模拟器中它不能正常播放(我只能听到音频 - 没有视频),并且在设备上它根本不起作用。它还说: MPMoviePlayerController 可能不支持''类型的文件

因此,我决定进行调查并尝试使用 NSURLConnection 下载文件。在 didReceiveResponse 方法中,我得到 [response expectedContentLength] 为 -1,[responseSuggestedFilename] 为 127.0.0.1.dms。

顺便说一句,我尝试在 UIWebView 上使用此方法显示来自该服务器的 pdf 并且它有效。

谢谢

亚历克斯


4

0 回答 0