What is difference between URLWithString and fileURLWithPath of NSURL?

Ameet Dhas picture Ameet Dhas · Apr 19, 2013 · Viewed 12.7k times · Source

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.

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?

Answer

Lily Ballard picture Lily Ballard · Apr 19, 2013

+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: 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.

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.