NSURL 的 URLWithString 和 fileURLWithPath 有什么区别? [英] What is difference between URLWithString and fileURLWithPath of NSURL?

查看:26
本文介绍了NSURL 的 URLWithString 和 fileURLWithPath 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我必须使用 URLWithString 播放流(HLS)视频和 fileURLWithPath 播放本地视频.

In my code I have to use URLWithString to play streaming(HLS) video and fileURLWithPath to play local video.

这两种方法有什么区别?我应该如何使用单一方法播放两个视频.

What is the difference between these two methods? How should I use single method to play both videos.

HSL 视频结束时,我还需要将最后一帧显示为静止图像.它现在在结束时显示空白屏幕.我应该如何实现这一目标?

Also I need to show last frame as still image when HSL video ends. Its now showing blank screen when it ends. How should i achieve this?

推荐答案

+URLWithString: 产生一个 NSURL 表示给定的字符串.因此,字符串可能是 @"http://www.google.com",而 URL 表示 http://www.google.com.

+URLWithString: produces an NSURL that represents the string as given. So the string might be @"http://www.google.com" and the URL represents http://www.google.com.

+fileURLWithPath: 采用路径,而不是 URL,并生成一个 NSURL 表示使用 file:// URL 的路径.所以如果你给它 /foo/bar/baz 的 URL 将代表 file:///foo/bar/baz.

+fileURLWithPath: takes a path, not a URL, and produces an NSURL that represents the path using a file:// URL. So if you give it /foo/bar/baz the URL would represent file:///foo/bar/baz.

您当然可以手动构造一个文件 URL 字符串并将其传递给 +URLWithString:,但是 +fileURLWithPath: 在您已经有了路径时使用起来更简单,因为您不必处理转义字符串并将其强制转换为 URL 格式.

You can of course construct a file URL string manually and pass it to +URLWithString:, but +fileURLWithPath: is simpler to use when you already have a path, as you don't have to deal with escaping the string and coercing it to a URL format.

这篇关于NSURL 的 URLWithString 和 fileURLWithPath 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆