Playing audio on iPad

后端 未结 5 787
囚心锁ツ
囚心锁ツ 2020-12-16 15:00

I\'m working on a website that has a chat for a client, however, we\'re experiencing problems with audio in iPad (iOS 5).

The target is in fact the iPad with support

5条回答
  •  没有蜡笔的小新
    2020-12-16 15:20

    The Apple iPad does not allow playing sounds without a user click previously initiating it.

    Solution: Add a play/pause button.

    App.toggle_audio = function(elem) {
      var icon = elem.find("i");
      var playing = _.include(icon.attr('class').split(" "), "icon-pause")
      if (playing) {
        elem.html(" " + App.translate_play_audio);
        App.play_audio_toggle = false;
      } else {
        App.audio_file.load();
        elem.html(" " + App.translate_pause_audio);
        App.play_audio_toggle = true;
      }
    }
    

    Once the user clicked the button once the Audio is loaded. You can then play it via Javascript.

      if (App.play_audio_toggle) {
        App.audio_file.play();
      }
    

提交回复
热议问题