且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

嵌入式***视频启动时如何停止播放音乐?

更新时间:2023-12-04 08:50:28

检测玩家的状态变化( onStateChange event)使用JavaScript: https://developers.google.com/***/js_api_reference #Events

Detect the player's state change (onStateChange event) using JavaScript: https://developers.google.com/***/js_api_reference#Events

如果使用 iframe 加载视频(如评论所示),请参阅 ***指南 iframe 嵌入(请注意代码检测玩家事件的样本。)

If the video is loaded using an iframe (as the comments indicate) see Guide for *** iframe embeds (note the code sample which detects player events).

示例

  function on***IframeAPIReady() {
    player = new YT.Player('player', {
      height: '390',
      width: '640',
      videoId: 'u1zgFlCw8Aw',
      events: {
        'onStateChange': onPlayerStateChange
      }
    });
  }

  function onPlayerStateChange(event) {
    if (event.data == YT.PlayerState.PLAYING) {
      // code to stop the audio player should probably go here
    }
  }

播放器启动时,使用JavaScript停止音频。你没有告诉我们它是如何嵌入到页面中的,但几乎所有玩家都可以用脚本停止(甚至 bgsound 也可以被黑客攻击)。

When the player starts, use JavaScript to stop the audio. You haven't told us how it is embedded into the page, but nearly any player can be stopped with script (even bgsound can be hacked).

并鼓励您的客户在页面加载时不自动播放音乐。从纯粹的商业角度来看,它可能会让您的客户付出代价。

And encourage your client to not auto-play music when the page loads. From a pure business standpoint, it can cost you customers.