iPhone:initWithContentURL 不播放视频

发布于 2024-12-04 08:35:23 字数 879 浏览 0 评论 0原文

I have a .mp4 video url in my server and trying to play by using the following code. But it doesn't do any actions when click on play button. I'm trying to test on iPhone 4.0 simulator or iPod 4.1 device. Is there anything wrong here (or) can't it work on iOS 4.0 or 4.1?

NSURL *url = [NSURL fileURLWithPath:encodedURL];
MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[self.view addSubview:videoPlayer.view];
videoPlayer.view.frame = CGRectMake(0, 0, 320, 480);
[videoPlayer play];

请指教!

Encode function:

NSString *newString = [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR("?#[]@!$ &'()*+,;=\"<>%{}|^~`"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) autorelease];

I have a .mp4 video url in my server and trying to play by using the following code. But it doesn't do any actions when click on play button. I'm trying to test on iPhone 4.0 simulator or iPod 4.1 device. Is there anything wrong here (or) can't it work on iOS 4.0 or 4.1?

NSURL *url = [NSURL fileURLWithPath:encodedURL];
MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[self.view addSubview:videoPlayer.view];
videoPlayer.view.frame = CGRectMake(0, 0, 320, 480);
[videoPlayer play];

Please advise!

Encode function:

NSString *newString = [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR("?#[]@!$ &'()*+,;=\"<>%{}|^~`"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) autorelease];

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

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

发布评论

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

评论(1

橘虞初梦 2024-12-11 08:35:23

如果文件位于服务器上,则以下行:

NSURL *url = [NSURL fileURLWithPath:encodedURL];

应该是:

NSURL *url = [NSURL URLWithString:encodedURL];

您还应该仔细检查控制台的 NSlog 字符串是否正确。

If the file is on a server than the line:

NSURL *url = [NSURL fileURLWithPath:encodedURL];

should be:

NSURL *url = [NSURL URLWithString:encodedURL];

You should also double check that the string encodedURL is correct by NSlog to your console.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文