We have an iOS app built with PhoneGap / Cordova 4.3.0. This app directly loads an external website by using <content src="http://example.com/foo" />
in the config.xml
file. All the functionality is contained within this website, so we are not actually using any local HTML or JS files.
As part of the app functionality, we must play some videos. Because the app is designed to work offline as well, we want to cache these videos locally. Therefore we are downloading them to the device using the FileTransfer plugin, along with other resources such as images or PDFs. After downloading the files we are getting URLs with the file://
protocol. We also have the option of using the cdvfile://
protocol. When we use cdvfile://
URLs to show images, the images show up correctly. However, videos do not play at all.
To play videos we are using standard HTML5 video tags:
<video width="auto" height="100%" controls="controls" autoplay="true">
<source src="..." type="video/mp4" />
</video>
The videos themselves are working, and they will play correctly from an external source (as in, they will play if we are accessing them from the server instead of the local filesystem). I realize that the problem has something to do with web-related concepts such as the same-origin policy and with the restriction to access the local filesystem. However, at the same time I must wonder why it is that images are working fine under these same constraints.
What I have tried so far:
- Using
file://
andcdvfile://
URLs as thesrc
of the video. This does not produce any sort of visual effect. The screen is simply black. - Using an
iframe
with thesrc
set to the video URL. When usingfile://
, the screen is still black. However, when usingcdvfile://
, the iOS video player interface appears, with a play button and a full-screen button, but the video does not play and there is no timeline either. - Adding a local file to cordova called
video.html
which takes a URL as parameter and renders avideo
tag with that URL assrc
. The plan was to include this file as aniframe
, but apparently I can't make aniframe
to a local file. I have tried various URLs that might point to that particularvideo.html
file (though in truth I'm not sure this is possible). Among the ones I tried were:cordova.file.applicationDirectory + 'www/video.html'
,http://localhost/www/video.html
,cdvfile://localhost/www/video.html
. - I looked for some cordova plugin that will play videos, but I have been unsuccessful in finding one for iOS. Most plugins seem to be targeted towards Android.
Now, it's possible that I'm going about this in a wrong way. As I see it, the "standard use case" for cordova is that you store your HTML/JS/CSS files locally. External content like the one I'm using is probably a bit unusual. I will explain the requirements for this app that have brought me to use this functionality.
- The app is supposed to be built for multiple platforms (though we're starting with iOS). Therefore we are using PhoneGap.
- It is supposed to be accessible both online and offline, though all the content comes from the server (no content is produced locally). This is why we are downloading content and saving it locally.
- It is also supposed to auto-update any part of itself on the fly, without requiring an update from the App Store. This is why we are using an external page - because it has a
cache.manifest
that allows us to control updates to the web app code, while at the same time allowing it to be cached locally. This is probably the most important thing to consider, because if we wanted to keep some files locally within Cordova, we would have to re-implement this cache functionality within Javascript (using as thin a layer as possible).
In any case, my main concern is how to get these videos working. I am willing to try the hackiest workarounds! If it's really not possible with the current development decisions, then maybe you could give me some hints as to how I should structure the app in order to make it work and still fulfill my requirements.
Thank you very much!