所以基本上我已经嵌入了一个不应该自动播放的视频,并且当播放被静音时,代码工作正常,但我只希望它运行onStateChange函数,否则无论何时播放/暂停视频,它都会使视频静音。有谁知道如何将该功能限制为单次执行?非常感谢帮助:)
function onYouTubeIframeAPIReady() {
player = new YT.Player('video-placeholder', {
videoId: 'sAhYEfQ1168',
playerVars: {
'autoplay': 0,
'controls': 0,
'autohide': 1,
'wmode': 'opaque',
'showinfo': 0,
'loop': 1,
'fs':0,
'rel':0
},
events: {
'onReady': onPlayerReady
}
});
}
function onPlayerReady(event) {
player.mute();
}
答案 0 :(得分:3)
您可以将onReady
对象的player.events
属性设置为null
onPlayerReady
函数的最后一行内的function onPlayerReady(event) {
player.mute();
player.events.onReady = null;
}
public static void main(String[] args) throws UnsupportedEncodingException {
String test= "İİİİİİİİİİ";
System.out.println("test.length() = " + test.length()); // out: 10
byte[] bytesOrig;
bytesOrig = test.getBytes("UTF-8"); // but after get bytes will return 20
System.out.println("bytesOrig.length = " + bytesOrig.length); // it
System.out.println("bytesOrig="+new String(bytesOrig));
byte[] bytesFive = new byte[10]; // 1. so change here to twice
System.arraycopy(bytesOrig, 0, bytesFive, 0, 10); // 2. change here also
System.out.println("bytes-Five="+new String(bytesFive));
System.out.println("Substring="+test.substring(0,5));
System.out.println("Substring real length=" + test.substring(0,5).getBytes().length);
}
答案 1 :(得分:1)
似乎“onStateChange”使用以下状态:
-1 (unstarted)
0 (ended)
1 (playing)
2 (paused)
3 (buffering)
5 (video cued)
文档:https://developers.google.com/youtube/iframe_api_reference?hl=de
数据为“-1”的事件似乎在第一次运行时只执行一次。
以下是一个例子:
如果您只想将视频静音,您还可以查看“onReady”事件。