iPhone:initWithContentURL 不播放视频
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果文件位于服务器上,则以下行:
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.