question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[iOS] play local file from Documents directory

See original GitHub issue

The player item is initialized to be able to play remote file or local file from the bundle. Init the URL using the [NSURL fileURLWithPath:uri]; can play local files not only from the bundle instead from the Documents folder. Really useful when the app created and saved the video itself (e.g. using the camera), and can specify an absolute path to the file locally. At this case the [[NSBundle mainBundle] pathForResource:uri ofType:type] will result nil.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
balazsnemethcommented, Mar 18, 2016

I made this fix, here is the code to play all three type of asset:

  • asset from the network
  • asset from the app bundle
  • asset from locally stored by the app (e.g in the Documents folder).

Replace these lines (242-244) from RTCVideo.m:

NSURL *url = (isNetwork || isAsset) ?
[NSURL URLWithString:uri] :
[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]];

to:

NSURL *url = nil;
if (isNetwork) {
    //Load based on the URL
    url = [NSURL URLWithString:uri];
}
else if (isAsset) {
    //Local asset: Can be in the bundle or the uri can be an absolute path of a stored video in the application

    //Check whether the file loaded from the Bundle,
    NSString *localPath = [[NSBundle mainBundle] pathForResource:uri ofType:type];
    if (localPath) {
        //Let's replace the `uri` to the full path'
        uri = localPath;
    }
    url = [NSURL fileURLWithPath:uri];
}

1reaction
kitologcommented, Mar 25, 2016

What link format for video in Documents must be after changing this code? file:///Users/user/Library/Developer/CoreSimulator/Devices/75TD86BA9-0H5E-7D9F-ND5G-349B2564093R/data/Containers/Data/Application/832F2C85-0F81-81E4-BB99-11E1B8A83053/Documents/videos/fcb5bf32a5cb108f278f2b911e728363.mp4 Like this?

Not working. URL started with uri://…, file://…, or simply /… not working after this changes in RTCVideo.m

Read more comments on GitHub >

github_iconTop Results From Across the Web

View and modify files and folders in Files on iPhone
In Files on iPhone, view and modify files stored in iCloud Drive and on iPhone, ... Enter a filename, folder name, or document...
Read more >
ios - How to play stored file in document directory as Local ...
I'm trying to play a sound track stored in my documents directory . when i get this sound and play it in avplayer...
Read more >
[iOS] play local file from Documents directory #167 - GitHub
Init the URL using the [NSURL fileURLWithPath:uri]; can play local files not only from the bundle instead from the Documents folder.
Read more >
Writing data to the documents directory - a free Hacking with iOS
Fortunately, iOS makes it very easy to read and write data from device storage, and in fact all apps get a directory for...
Read more >
How to Add a Local Folder to Your iPhone or iPad - Medium
You can save files to Documents' storage area from any app that can save to the Files app. all files, what you save...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found