v2.5.2
Giriş yap

Javascript audio otomatik oynattırma

emmir2
555 defa görüntülendi
    var jPlayerAndroidFix = (function($) {
      var fix = function(id, media, options) {
        this.playFix = false;
        this.init(id, media, options);
      };
      fix.prototype = {
        init: function(id, media, options) {
          var self = this;
          this.id = id;
          this.media = media;
          this.options = options;
          this.player = $(this.id);
          this.player.bind($.jPlayer.event.ready, function(event) {
          self.setMedia(self.media);
          });
    
          // Apply Android fixes
          if($.jPlayer.platform.android) {
    
            // Fix playing new media immediately after setMedia.
            this.player.bind($.jPlayer.event.progress, function(event) {
              if(self.playFixRequired) {
                self.playFixRequired = false;
                if(self.playFix) {
                  self.playFix = false;
                  $(this).jPlayer("play");
                }
              }
            });
            this.player.bind($.jPlayer.event.ended, function(event) {
              if(self.endedFix) {
                self.endedFix = false;
                setTimeout(function() {
                  self.setMedia(self.media);
                },0);
              }
            });
            this.player.bind($.jPlayer.event.pause, function(event) {
              if(self.endedFix) {
                var remaining = event.jPlayer.status.duration - event.jPlayer.status.currentTime;
                if(event.jPlayer.status.currentTime === 0 || remaining < 1) {
                  setTimeout(function() {
                    self.jPlayer._trigger($.jPlayer.event.ended);
                  },0);
                }
              }
            });
          }
    
          this.player.jPlayer(this.options);
          this.jPlayer = this.player.data('jPlayer');
          this.cssSelectorAncestor = this.player.jPlayer('option', 'cssSelectorAncestor');
          this.resetAndroid();
          return this;
        },
        setMedia: function(media) {
          this.media = media;
          this.resetAndroid();
          this.player.jPlayer("setMedia", this.media);
          return this;
        },
        play: function() {
          if($.jPlayer.platform.android && this.playFixRequired) {
            this.playFix = true;
          } else {
            this.player.jPlayer("play");
          }
        },
        resetAndroid: function() {
          if($.jPlayer.platform.android) {
            this.playFix = false;
            this.playFixRequired = true;
            this.endedFix = true;
          }
        }
      };
      return fix;
    })(jQuery);
    
    $(document).ready(function() {
    
      var id = "#radyo_play";
      var bubble = {
        title:"Radyo Player",
        m4a:"<?= $cek['radyo'] ?>",
      };    
      var options = {
        swfPath: "js\jplayer",
        supplied: "m4a",
        wmode: "window",
        useStateClassSkin: true,
        autoBlur: true,
        smoothPlayBar: true,
        keyEnabled: false,
        remainingDuration: true,
        toggleDuration: true
      };
    
      var myAndroidFix = new jPlayerAndroidFix(id, bubble, options);
    
      $('#setMedia-Bubble').click(function() {
        myAndroidFix.setMedia(bubble);
      });
      $('#setMedia-Bubble-play').click(function() {
        myAndroidFix.setMedia(bubble).play();
      });
    

    
    });
    //]]>
 <div id="radyo_play" class="jp-jplayer" style="width: 0px; height: 0px;">
    <img id="jp_poster_0" style="width: 0px; height: 0px; display: none;">
    <audio src="<?= $cek['radyo'] ?>" title="<?= $cek['title'] ?>" controls autoplay loop></audio>
  </div>

Normalde <audio içine controls autoplay ekleyince otomatik oynatıyordu lakin araya javascript girince ne yaptıysam otomatik başlattıramadım

Cevap yaz
Cevaplar (1)
laedriman
1161 gün önce

Mediaları (video veya audio) otomatik başlatamazsınız. Browserlar buna izin vermez. Muted modda başlatabilirsin ancak.