I’m trying to retrieve a video from the local web app running on iOS / Cordova, base64 encoding it and then serving the src in a video element (the idea is to save the base64 later on but for testing purposes and because saving it wasn’t working I’m serving it up within a video element for now).
The video loads up and plays fine when I link to it from the local web app like so:
<video src="/local-filesystem/var/mobile/Containers/Data/Application/##########-####-####-####-################/Library/NoCloud/testvideo123.mp4"></video>
But when I try and fetch it through XHR and convert it to base64, it doesn’t play and I get a MEDIA_ERR_SRC_NOT_SUPPORTED error from the video element:
// Function to fetch a file from meteor's local web server in base64
function getBlobURL(url, callback) {
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.send();
}
var url = '/var/mobile/Containers/Data/Application/##########-####-####-####-################/Library/NoCloud/testvideo123.mp4';
var file = '/local-filesystem' + url;
getBlobURL(file, function (base64video) {
console.log(base64video.substr(0,200)); // logging first 200 characters of the video base64 string (see below)
$('div').append('<video src="'+base64video+'" autoplay controls playsinline webkit-playsinline></video>');
});
Here are the first 200 characters from the base64 encoded string:
data:video/mp4;base64,AAAAFGZ0eXBxdCAgAAAAAHF0ICAAAAAId2lkZQAAAABtZGF0AMxABwDume5NmehMFWjKCUoVE58eL543GCwAdL/OAAAAAHYNjhAP+J6AA4H/lgHx77IAAFeL/F9oAAHS+b1OzAAD5D6brvIAAAAfb9P3vx/73uAAAA/zf2b9M4v9n92AAA
Any help with this would be greatly appreciated as I don’t have any experience with the FileReader class and am completely out of ideas.