Comments (9)
@bfred-it https://reactjs.org/docs/refs-and-the-dom.html, I am not the original issue autor, just trying to help how to integrate your library with React.
from iphone-inline-video.
I’d need your full code. Are you using <source>
and/or changing the src
after initialization?
from iphone-inline-video.
I found it to not work with react when I tried it a while back, my solution was to create a div and manually create the video element and inserting it into the react div. It's a bit dirty but it did the trick just fine.
from iphone-inline-video.
If anyone provides a repro I can look into it.
There are other issues opened by people trying it with react, maybe they have the solution.
from iphone-inline-video.
I just remembered, I needed this workaround as React doesn't pass on the muted
prop as expected.
So this is what I did (simplified):
class Player extends React.Component {
// Dom References
video;
videoContainer;
addVideoToContainer = div => {
const { url, mutedDefault = true } = this.props;
// Doing the ref stuff unfortunately requires some workarounds
if (div === null) {
return;
}
this.videoContainer = div;
// Unfortunately we need to hack our way around React not passing on the "muted" prop as expected, without it iOS ( and Android ) won't allow autoplay at all
this.videoContainer.innerHTML = `
<video src="${url}" autoplay ${mutedDefault
? "muted"
: ""} playsinline id="video_1" style="width: 100%; height: 100%; z-index: 2; position: absolute; top: 0; left: 0;"></video>
`;
const video = this.videoContainer.querySelector("video");
if (!video || !(video instanceof HTMLVideoElement)) {
throw new Error("Expected Video Element");
}
this.video = video;
this.video.addEventListener("loadedmetadata", this.videoMetadata, false);
this.video.addEventListener("play", this.videoPlay, false);
this.video.addEventListener("timeupdate", this.videoTimeUpdate, false);
this.video.addEventListener("pause", this.videoPaused, false);
this.video.addEventListener("ended", this.videoEnded, false);
this.video.addEventListener("contextmenu", this.videoContextmenu, false);
this.video.addEventListener("click", this.videoContextmenu, false);
this.video.addEventListener("seeking", this.videoSeeking, false);
this.video.addEventListener("waiting", this.videoMetadata, false);
this.video.addEventListener("playing", this.videoMetadata, false);
};
videoMetadata = () => {};
videoPlay = () => {};
videoTimeUpdate = () => {};
videoPaused = () => {};
videoEnded = () => {};
videoContextmenu = () => {};
render() {
const { state, mutedDefault = true } = this.props;
return <div ref={this.addVideoToContainer} />;
}
}
This works perfectly fine for me in production
from iphone-inline-video.
I’m sure that’s unnecessary, you need to IIV on the real dom element, not on the react component. IIV should not go through React so there’s no prop that it wouldn’t “pass”
from iphone-inline-video.
We do it like this:
initPolyfill(this.video, {
iPad: true,
muted: this.state.muted
})
Where this.video
is a ref
from iphone-inline-video.
A ref to what? I’d need more of the code to understand where it’s being called.
Muted isn’t a parameter anymore, it just reads the attribute.
from iphone-inline-video.
@montogeek Thanks, the sounds like the correct way.
from iphone-inline-video.
Related Issues (20)
- Handle autoplay state and events correctly HOT 1
- Some properties don't work in fullscreen
- Test HOT 1
- Test
- Replace ಠ with IIV? HOT 5
- Some warnings/errors when installing with npm v5.0.3 HOT 1
- [iOS] Autoplay doesn't work with css prop display:none HOT 1
- Use the iphone-inline-video with vidoe. Js HOT 1
- Would this library work on non-webGL devices? HOT 3
- It doesn't work for in-app video HOT 1
- [Deprecation] 'HTMLVideoElement.webkitDisplayingFullscreen' is deprecated. Please use 'Document.fullscreenElement' instead. HOT 4
- option to force IIV to be used on iOS 11 when in low power mode HOT 1
- vpaid enabled ? HOT 1
- Is there a way to do this on an iframe element instead of <video>? HOT 1
- Common and es modules HOT 2
- ios11.2.5
- video.pause is not a function. in Chrome device Mode with iPhone simulations only. (React) HOT 1
- Control bar not Hidden HOT 1
- React uses enableInlineVideo to cause the ios8 and 9 devices to play video abnormally HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iphone-inline-video.