Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用YouTube嵌入API更新带有视频标题的HTML文本_Javascript_Html_Youtube_Youtube Api - Fatal编程技术网

Javascript 使用YouTube嵌入API更新带有视频标题的HTML文本

Javascript 使用YouTube嵌入API更新带有视频标题的HTML文本,javascript,html,youtube,youtube-api,Javascript,Html,Youtube,Youtube Api,目前正在努力找出如何在使用YouTube嵌入API播放新视频时更新带有YouTube标题的文本字符串 以下是我要更新的相关HTML段: <div id="bottom-song-title" class="song-name">No song is playing</div> 我尝试使用innerHTML技术,但无法更新字符串。有什么想法吗 供您查看的当前站点: 谢谢 在这里回答我自己的问题,我就是这样做到的: document.getElementById(“底部歌曲

目前正在努力找出如何在使用YouTube嵌入API播放新视频时更新带有YouTube标题的文本字符串

以下是我要更新的相关HTML段:

<div id="bottom-song-title" class="song-name">No song is playing</div>
我尝试使用innerHTML技术,但无法更新字符串。有什么想法吗

供您查看的当前站点:


谢谢

在这里回答我自己的问题,我就是这样做到的:

document.getElementById(“底部歌曲标题”).textContent=event.target.getVideoData().title

希望这对别人有帮助

function onPlayerStateChange(event) {
    if (event.data == YT.PlayerState.ENDED) {
        console.log("END!");
        clearTimeout(timeout_setter);
        document.getElementById("progress-bar-bottom").style.cssText = "transition: none;";
    } else if (event.data == YT.PlayerState.PLAYING) {
        console.log("PLAYING");
        loopy();
        document.getElementById("progress-bar-bottom").style.cssText = "transition: all 1s linear 0s;";
    } else {
        console.log(event.data);
    }

    var state = player.getPlayerState();
    if (state == 1) {
        jQuery('#media-toggle').click(function (event) {
            player.pauseVideo();
        });
    } else {
        jQuery('#media-toggle').click(function (event) {
            player.playVideo();
        });
    }
    if (state == 1) {
        jQuery('#media-toggle-bottom').click(function (event) {
            player.pauseVideo();
        });
    } else {
        jQuery('#media-toggle-bottom').click(function (event) {
            player.playVideo();
        });
    }
    if (state == 1) {
        jQuery('.media-circle').click(function (event) {
            player.pauseVideo();
        });
    } else {
        jQuery('.media-circle').click(function (event) {
            player.playVideo();
        });
    }
}