我的mediaelement.js播放器无法正确加载

时间:2018-02-06 21:41:03

标签: javascript php html iframe mediaelement

我正在将mediaelement.js播放器整合到我的网站上。当我配置播放按钮以使播放器出现时,它不会加载整个播放器。我必须按三次播放按钮才能加载播放器。

当我按下按钮时,iframe会打开:

<a href="javascript:;" data-id="<?php echo $video['id']['videoId'];?>" data-title="<?php echo htmlspecialchars( $video['snippet']['title'] ); ?>" data-source="youtube" id="ic<?php echo $video['id']['videoId'];?>" class="btn-play"><button type="button" class="btn btn-success btn-md" style="width: 100%;"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> <?php echo $search_play_but; ?></button></a>
<div id="player-<?php echo $video['id']['videoId'];?>" class="player clearfix">

这是iframe代码:

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/mediaelement/latest/mediaelement-and-player.min.js"></script>
    <script>$('audio').mediaelementplayer();</script>
    <?php
    require_once('../admin/config.php');
    require_once('../includes/url_slug.php'); 

    $json = file_get_contents('https://www.googleapis.com/youtube/v3/videos?id='.$_GET["id"].'&key='.$youtube_key.'&part=snippet');
    $yt_data = json_decode($json);
    $yt_id = $_GET["id"];
    ?>

    //this is the iframe
    <div id="player-<?php echo $video['id']['videoId'];?>" class="player clearfix"></div>

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/mediaelement/latest/mediaelementplayer.css">

    <script>
        MediaElement('player1', {success: function(me) {    
        me.play();
        }});
    </script>
    <body>
        <audio preload="auto" id="player1" preload="none" controls>
            <source autoplay="true" src="https://www.youtube.com/watch?v=<?php echo $yt_id; ?>" type="video/x-youtube">
        </audio>
<?php 
 $count++; 
?>

当它只是玩家时,它会立即加载:

http://escuchala.com/includes/youtube.php?id=VRJmcxCrAOA

但是在搜索中你必须按三次按钮才能播放:

http://escuchala.com/music/si-tu-no-estas-antonio-cartagena

1 个答案:

答案 0 :(得分:0)

这就是我所说的: 在escuchala.com/includes/youtube.php?id=Htu3va7yDMg

播放器显示一次。准备播放音乐。

检查图像

first click

second click

in the third click it works as it should.