【问题标题】:IOS 10 mobile audio.play() work unstableIOS 10 mobile audio.play() 工作不稳定
【发布时间】:2017-09-07 09:40:58
【问题描述】:

这是我的代码:

$(document).on('click', 'div.play',function () {
play = $(this);
var stop = $('.stop');
contentId = play.attr('id');
nexttrack = nexttrackPlay(play);

if(!play.parent().hasClass('stop')) {
  if(song ==undefined){
    initAudio(play);
  }
  else
  {
    song.src = play.attr('audiourl');
    song.load();
  }

  playerInit(play);
  stop.each(function () {
    $(this).removeClass('stop');
  });

  playAudio();
}
else{
  if(song.paused){
    playAudio();
  }
  else{
    stopAudio();
  }
}


 });

function initAudio(elem) {
var url = elem.attr('audiourl');
song = document.getElementsByTagName('audio')[0];
console.log(song);
song.src = url;
song.preload = 'metadata';
song.load();
    song.addEventListener('play', function () {
  $('.play-play').addClass('stop');
  play.parent().addClass('stop');
  play.removeClass('pause');
  $('.button-play').addClass('stop');
      song.removeEventListener('play',function(){  });
},false);

song.addEventListener('pause', function () {
  play.addClass('pause');
  $('.play-play').removeClass('stop');
  $('.button-play').removeClass('stop');
  song.removeEventListener('play',function(){  });
},false);


}
  function playAudio() {
    song.load();
  song.play();
  }
  function stopAudio() {
    song.pause();
  }

在 Android 和桌面上完美运行,但在 IOS 上第一次点击不起作用,当点击另一首歌曲然后再次开始播放时。

【问题讨论】:

  • 我们需要的远不止这些

标签: ios html audio playback


【解决方案1】:

我发现了问题和解决方案) 一切都在标头中,我发送了带有 Content-type:application/octet-stream 的标头,这对 IOS 来说是个问题,然后我将其更改为音频/mpeg 并开始加载音频。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 1970-01-01
    • 2017-05-21
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多