Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable sound in a youtube embed

Status
Not open for further replies.

jruizfdez

Technical User
Aug 1, 2008
7
ES
Hi,

I have a youtube embed and I'd like to add it in my blog but this embed plays a video with its sound default activated.

Could I deactivated its default sound in order to this sound activated only when users click on a buttom?

This is the code:

Code:
<object width="300" height="250"><param name="movie" value="[URL unfurl="true"]http://www.youtube.com/v/WL4f3is0ewk&hl=es&autoplay=1"></param><embed[/URL] src="[URL unfurl="true"]http://www.youtube.com/v/WL4f3is0ewk&hl=es&autoplay=1"[/URL] type="application/x-shockwave-flash" width="300" height="250"></embed></object>

Thanks
 
Hi,

I deactivated the default sound but now, I still have a problem.

I'd like to genetate a loop with this video in order to start the player when it finished, do you know?

This is the code now:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
      YouTube Javascript API Example page
    </title>
    <script src="[URL unfurl="true"]http://swfobject.googlecode.com/svn/tags/rc3/swfobject/src/swfobject.js"[/URL] type="text/javascript"></script>
    <style type="text/css">

    body {
      font-family: verdana, helvetica;
      background-color: white;
    }

    #timedisplay {
      border: solid 1px red;
      width: 50px;
    }
    </style>
    <script type="text/javascript">

        function updateHTML(elmId, value) {
          document.getElementById(elmId).innerHTML = value;
        }

        function setytplayerState(newState) {
          updateHTML("playerstate", newState);
        }

        function onYouTubePlayerReady(playerId) {
          ytplayer = document.getElementById("myytplayer");
          setInterval(updateytplayerInfo, 250);
          updateytplayerInfo();
          ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
          ytplayer.addEventListener("onError", "onPlayerError");
        }

        function onytplayerStateChange(newState) {
          setytplayerState(newState);
        }

        function onPlayerError(errorCode) {
          alert("An error occurred: "+ errorCode);
        }

        function updateytplayerInfo() {
          updateHTML("bytesloaded", getBytesLoaded());
          updateHTML("bytestotal", getBytesTotal());
          updateHTML("videoduration", getDuration());
          updateHTML("videotime", getCurrentTime());
          updateHTML("startbytes", getStartBytes());
        }

        // functions for the api calls
        function play() {
          if (ytplayer) {
            ytplayer.playVideo();
          }
        }

        function pause() {
          if (ytplayer) {
            ytplayer.pauseVideo();
          }
        }

        function stop() {
          if (ytplayer) {
            ytplayer.stopVideo();
          }
        }

        function getPlayerState() {
          if (ytplayer) {
            return ytplayer.getPlayerState();
          }
        }

        function seekTo(seconds) {
          if (ytplayer) {
            ytplayer.seekTo(seconds, true);
          }
        }

        function getBytesLoaded() {
          if (ytplayer) {
            return ytplayer.getVideoBytesLoaded();
          }
        }

        function getBytesTotal() {
          if (ytplayer) {
            return ytplayer.getVideoBytesTotal();
          }
        }

        function getCurrentTime() {
          if (ytplayer) {
            return ytplayer.getCurrentTime();
          }
        }

        function getDuration() {
          if (ytplayer) {
            return ytplayer.getDuration();
          }
        }

        function getStartBytes() {
          if (ytplayer) {
            return ytplayer.getVideoStartBytes();
          }
        }

        function mute() {
          if (ytplayer) {
            ytplayer.mute();
          }
        }

        function unMute() {
          if (ytplayer) {
            ytplayer.unMute();
          }
        }
    </script>
  </head>
  <body id="page">
  <div>
    <div id="ytapiplayer">
    </div>
    <script type="text/javascript">

      // allowScriptAccess must be set to allow the Javascript from one domain to access the swf on the youtube domain
      var params = { allowScriptAccess: "always" };
      // this sets the id of the object or embed tag to 'myytplayer'. You then use this id to access the swf and make calls to the player's API
      var atts = { id: "myytplayer" };
      swfobject.embedSWF("[URL unfurl="true"]http://www.youtube.com/v/WL4f3is0ewk&hl=es&autoplay=1;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayer",[/URL] 
                         "ytapiplayer", "300", "250", "8", null, null, params, atts);

    </script>
    
    
  </body>
</html>

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top