问题
I'm trying to implement live video from youtube channel with youtube iframe api. There is a videoId property in api and it works for live videos too but we have to add video id every stream start.
There is a solution in iframe live video https://www.youtube.com/embed/live_stream?channel=CHANNEL_ID
. How can i use it in iframe api?
回答1:
I came across this same issue. I figured out that you can directly add the iframe with the src instead of an empty div. Then give it an id and pass that to the new YT.Player instance.
ex:
html:
<iframe id="player" src="https://www.youtube.com/embed/live_stream?channel=CHANNEL_ID?enablejsapi=1"></iframe>
js:
var player = new YT.Player('player', {});
来源:https://stackoverflow.com/questions/47241553/youtube-iframe-api-for-live-videos