Noob question from a high school physics teacher: I have written a web app for my students to analyze videos using the HTML video player. If they take videos on their iPhones, copy them to their chromebooks, and then edit the file extension from .mov to .mp4, things work fine. Is there a way to skip the extension change? I have seen examples like this:
source src="https://www.somewebsite.com/videos/sample.mov" type="video/mp4"
where the call to the file is embedded in the code. But my students are making their own videos, so they need to be able to load them.
I tried
inputFile.type = "video/mp4"
but the type seems to be read only, because when I read it back, it is still "video/quicktime"
I figured out a solution to my own question, a personal first!
var file = files[0]; // this is the quicktime file I want to read
var dummyName = file.name;
file = new File([file], dummyName, {type: "video/mp4"});
Now the variable file points to the original file, but is recognized as mp4 and can be played.
Related
So I want to make it a little bit more difficult for users to directly download MP3 files from the server (just from going straight to the URL of the source). I've been looking around and, from what I've gathered, a good way to go about this is to convert an Audio object to a use-once Blob (similar to how YouTube does it).
As an example, something like this:
<!-- directly accessible, unobfuscated url -->
<audio src="www.mywebsite.com/media.mp3"></audio>
Would become:
<!-- visiting the link would lead to a 'your file was not found' page
and the original url is now obfuscated -->
<audio src="blob:http://www.mywebsite.com/6fc4f9d2-035a-4999-b330-96da04c0f6a8"></audio>
At the moment, this is how I'm doing it:
var url = "http://www.mywebsite.com/media.php"; // media.php points to an mp3 file
var audio = null; // just for simplicity sake - i'm not actually doing it like this
if(!audio){
audio = new Audio(url);
} else {
audio.pause();
audio.src = url;
}
Now I was looking at this answer (along with a couple others), but they all either involve using a file selected from an input or, as this one is, using the file as a Base64 string and converting that to a Blob, which I can't figure out how to do and imagine to be a somewhat heavy task to do on the client-side.
Essentially, all I need to do is convert the url to a Blob that can only be used once in that session (cannot be directly accessed in another tab - just that one time it's being played, for example).
NOTE: I Tagged PHP as this may also be a server-side issue, feel free to correct that if necessary.
I am developing a video player application, which plays video videos (.mp4) from the local filesystem using node.js and electron (therefore I am using chromium's html5 video player).
Playing video videos larger than 2GB seems to be a problem with my current approach.
I used to read the local video files using fs.readFileSync and pass that Blob to the video player, like in this code:
this.videoNode = document.querySelector('video');
const file: Buffer = fs.readFileSync(video.previewFilePath);
this.fileURL = URL.createObjectURL(new Blob([file]));
this.videoNode.src = this.fileURL;
This does work for video files smaller that 2GB. Files larger than 2GB trigger the following error:
ERROR RangeError [ERR_FS_FILE_TOO_LARGE]: File size (2164262704) is greater than possible Buffer: 2147483647 bytes
at tryCreateBuffer (fs.js:328)
at Object.readFileSync (fs.js:364)
at Object.fs.readFileSync (electron/js2c/asar.js:597)
I believe the solution is to pass a ReadStream to the html5 video player using fs.readStream(). Unfortunately I cannot find any documentation on how to pass this stream to the video player.
As the topic says you are using electron and from the above comments it is clear that you are avoiding a server. It seems that if you are just creating an offline video player then you are just making things complex. Why are you creating a buffer and then creating a new url? You can achieve this by simply getting the video path and using it as src attribute of video object.
Your code should look like this-
var path="path/to/video.mp4"; //you can get it by simple input tag with type=file or using electron dialogs
this.videoNode = document.querySelector('video');//it should be a video element in your html
this.videoNode.src=path;
this.videoNode.oncanplay=()=>{
//do something...
}
This will handle complete file and you dont need to disable webPreference given that videoNode is the video element in html file.
You can take a look at this open source media player project made using electron-
https://github.com/HemantKumar01/ElectronMediaPlayer
Disclaimer: i am the owner of the above project and everyone is invited to contribute to it
Currently I'm creating a game in Javascript and there are audio files included in the game. It works perfectly in Chrome, but Firefox has some problem with decoding some of the audio files.
Here is the error message
I have read a post about the junk chunks at the beginning of the file, but I don't really know how to clean them or what to do with it.
Link of the post
// Error Code: NS_ERROR_DOM_MEDIA_METADATA_ERR (0x806e0006)
audio = new Audio("someaudio.wav")
// It has no problem with it
audio = new Audio("someotheraudio.wav")
I experienced that Firefox can decode some audio files, but not all of them.
I have worked with images, they seem to do well when you use the downloadURL() to embed them in html tags,but the video doesn't work.
I tried using the video and iframe tag in html but it doesn't work. From what I understand, is that incoming file is not a video but a general file, it downloads with ".mp4 extension. Please suggest what should I do. I am working on a small time project where users can upload videos and watch other user's video.
Use downloaded Url to play video in chat.
In this code, i have passed a video URI to which I want to get the downloadable URL and then set the source of the video element.
Note:- Remember to put the controls property to video tag.
this.storage.refFromURL(videoUri).getMetadata().then(function(metadata) {
console.log('metadata',metadata.downloadURLs[0]);
vidElement.src = metadata.downloadURLs[0];
});
I'm attempting to add sound to my HTML5 game using SoundJS, a free Javascript library (http://www.createjs.com/#!/SoundJS).
I'm testing it out using the most basic sample program that's included in the zip. It runs great when opening in a browser from my hard drive, but after uploading it, no sounds play when I load the page from the web. The sound files are in the exact same place and folder as on my pc.
Has anyone successfully gotten this to work?
Here's what I'm trying to run:
function init()
{
if (!createjs.Sound.initializeDefaultPlugins()) {return;}
var audioPath = "sounds/";
var manifest = [
{id:"Music", src:"18-machinae_supremacy-lord_krutors_dominion.ogg"},
{id:"Thunder", src:"Thunder1.ogg"}
];
createjs.Sound.alternateExtensions = ["mp3"];
createjs.Sound.addEventListener("fileload", handleLoad);
createjs.Sound.registerManifest(manifest, audioPath);
}
function handleLoad(event)
{
createjs.Sound.play(event.src);
}
I work on SoundJS and can confirm it works from servers, as you can see in the examples.
As the above comment says, the best place to start is in developer console in your browser.
Potential sources of the issue are not including or having the wrong path for the js files that are loaded in the script tags, not including / wrong path for the sound files, and possibly but unlikely not setting the correct mime types on your server to properly return audio files.
Hope that helps.