Our iOS app, developed using PhoneGap / Cordova 4.3.0, loads an external website directly utilizing
<content src="http://example.com/foo" />
in the config.xml
file. All functionality resides within this website, eliminating the need for local HTML or JS files.
To incorporate video playback functionality while maintaining offline access, we are caching videos locally on the device using the FileTransfer plugin alongside other resources like images and PDFs. Upon downloading, the files generate URLs with the file://
protocol, or alternatively, the cdvfile://
protocol. Surprisingly, while images display properly using cdvfile://
URLs, videos fail to play.
We have employed standard HTML5 video tags for playing the videos:
<video width="auto" height="100%" controls="controls" autoplay="true">
<source src="..." type="video/mp4" />
</video>
The videos function correctly when accessed externally (i.e., from the server instead of the local filesystem). This issue appears linked to web concepts such as the same-origin policy and restrictions accessing the local filesystem. The puzzling aspect is why images behave as expected under these constraints.
Approaches attempted thus far include:
- Using
file://
andcdvfile://
URLs as the videosrc
, resulting in a black screen devoid of any visual content. - Embedding an
iframe
with the video URL set as thesrc</code. While <code>file://
maintenance a black screen, switching tocdvfile://
unveils the iOS video player interface but fails to initiate video playback or provide a timeline. - Creating a local file named
video.html
inside Cordova, intending to invoke this file via aniframe
. Attempts to reference thevideo.html
file yielded inconclusive outcomes despite trying various URLs referencing it. Some attempts included:
,cordova.file.applicationDirectory + 'www/video.html'
http://localhost/www/video.html
,
.cdvfile://localhost/www/video.html
- Pursuing Cordova plugins for video playback specifically for iOS, without success as most plugins cater to Android platforms.
This unconventional use case within Cordova prompts reconsideration of our approach. Ordinarily, Cordova applications store HTML/JS/CSS files locally, unlike our scenario where all content originates from external sources. We have adapted this method due to specific app requirements which I will outline below.
- The intent is to deploy the app across multiple platforms initially targeting iOS, hence our use of PhoneGap.
- The app aims to be accessible both online and offline, with all content retrieved from the server (sans locally produced content), necessitating the download and local storage of online resources.
- Auto-updating capability without relying on App Store updates is desired, achieved through an external page with a
cache.manifest
ensuring control over web app code updates while permitting local caching. Noteworthy is that replicating this cache functionality within Cordova would entail significant JavaScript overhead.
My primary concern pertains to resolving the video playback issue at hand. I am open to exploring unconventional solutions! Should the current development choices render resolution unattainable, guidance on restructuring the application to meet the objectives while enabling video playback functionality will be greatly appreciated.
Thank you sincerely!