私はこのソリューションをChromeで動作させています:
ボタンがクリックされたときにjQueryを使用してオーディオファイルを再生する
しかし、firebugコンソールは次のように述べています。
HTTP "Content-Type" of "audio/mpeg" is not supported. Load of media resource http://path/to/sound.mp3 failed.
このスクリプトでoggファイルとmp3ファイルの両方を定義する方法はありますか(これにより、Firefoxでサウンドを再生できると仮定します):
<script>
$(document).ready(function() {
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'http://path.com/to/sound.mp3');
$('#play_it').click(function() {
audioElement.play();
});
});
</script>
ありがとうございました。
アップデート
私はmp3参照の下のファイルに別の参照を追加しようとしましたが、これが最善の解決策であるかどうかはわかりませんが、うまくいきました:
<script>
$(document).ready(function() {
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'http://path.com/to/sound.mp3');
audioElement.setAttribute('src', 'http://path.com/to/sound.ogg');
$('#play_it').click(function() {
audioElement.play();
});
});
</script>