fregante / iphone-inline-video

📱 Make videos playable inline on the iPhone (prevents automatic fullscreen)
https://npm.im/iphone-inline-video
MIT License
2.06k stars 298 forks source link

Can't toggle mute/sound #56

Open giannoudak opened 8 years ago

giannoudak commented 8 years ago

Hello, i use your solution to autoplay inline a video with the muted option set, but i can't figure out how i can play video sound afterwards.

i try to set video.muted = true/false on a button click but nothing actually happens. How can i trigger video button from an external click?

fregante commented 8 years ago

Last week I started some work to do exactly that, but it's not finished yet and I don't remember how well it worked: https://github.com/bfred-it/iphone-inline-video/tree/mute-toggle-test

For now you'll just have to have to separate <video> elements, one muted and the other one to replace it with

giannoudak commented 8 years ago

At first thanks for your immediate reply! this was really helpfull!

For your workaround you mention with two <video> elements, how they can be synchronized? As far i understand, say that we autoplay muted the one video, and with click on a sound button we trigger play for the other video on the first's currentTime. I'm on the right direction?

Also, actually do you have an estimation on that branch completion?

fregante commented 8 years ago

Something like this:

    //audioVideo.load() // not necessary, but may make the jump faster
    mutedVideo.onclick = function () {
        audioVideo.currentTime = mutedVideo.currentTime;
        mutedVideo.pause();
        audioVideo.play();
    }

This is probably going to take a bit to actually start playing, but maybe you can jumpstart that with the first line.

Not sure about when I can look into that, it's unlikely to be done before the end of next week.

GordanRatkovic commented 7 years ago

Any progress on this? I noticed you have an active branch for the mute-toggle feature.

reidblomquist commented 7 years ago

+1 would love to see this feature added

windchime18 commented 7 years ago

i think playing two videos simultaneously is not possible depending on the iOS version. I have also tried it and it worked on iOS9 but not on iOS10 Playing multiple videos side by side iOS #92

windchime18 commented 7 years ago

I think i have found a possible work around on this problem. you can use this code you should have a two videos. then a button to activate the function enable the 2nd video with sounds.

var video = document.getElementById("video_without_audio"); 
var myVideo = document.getElementById("video_with_audio");

function enableSound() {
    myVideo.load();
    myVideo.play();
    myVideo.pause();
    video.pause();
    $("#video_without_audio").css("display", "none");
    $("#video_with_audio").css("display", "block");
}

myVideo.addEventListener("canplay", function() {
// console.log(" canplay: before = " + myVideo.currentTime);
myVideo.currentTime = video.currentTime;
// console.log(" canplay: after = " + myVideo.currentTime);

if( myVideo.currentTime < 1 ) {
    myVideo.play();
}
else {
    setTimeout(checkStarted, 500);
}

}, false);

function checkStarted()
{ 
console.log("check started");
   myVideo.play();
}