unable to auto-play with mediaelement js in chrome

只谈情不闲聊 提交于 2019-12-24 12:12:22

问题


I am trying to autoplay audio from a live stream audio link: http://163.172.165.94:8728/;stream.mp3

I tried adding autoplay, and by doing:

$('#player2').mediaelementplayer({
    autoplay: true
});

nothing work, tried every single answer from stack overflow.

Can someone help me? What am I doing wrong?

<link rel="stylesheet" href="https://cdn.jsdelivr.net/mediaelement/latest/mediaelementplayer.css">

<div class="media-wrapper">
<audio id="player2" preload="auto" autoplay style="max-width:100%;">
<source src="http://163.172.165.94:8728/;stream.mp3" type="audio/mp3">
 </audio>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/mediaelement/latest/mediaelement-and-player.min.js"></script>
    <script>
    $('#player2').mediaelementplayer();
    </script>

回答1:


This will help you to auto play when it is loaded

<audio id="player2" preload="auto" autoplay style="max-width:100%;">
      <source src="<?php echo $audidec; ?>" type="audio/mp3">
</audio>


$('audio').mediaelementplayer({
    success: function (mediaElement) {
        mediaElement.play();
        mediaElement.addEventListener('ended', function (e) {
            alert("finished");
        }, true);
    }
});


来源:https://stackoverflow.com/questions/54815962/unable-to-auto-play-with-mediaelement-js-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!