【问题标题】:my mediaelement.js player does not load correctly我的 mediaelement.js 播放器无法正确加载
【发布时间】:2018-02-07 07:53:14
【问题描述】:

我正在将 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

【问题讨论】:

  • 在 Chrome 中我看到错误“Uncaught TypeError: $(...).mediaelementplayer is not a function”这似乎是由于匹配的 js 库没有像在单播放器页面。因此,我根本无法让播放器工作,更不用说只在点击 3 次后。
  • 解决:escuchala.com/includes/youtube.php?id=VRJmcxCrAOA
  • 在 youtube.php 的代码末尾我想念这个:` `
  • 同样的问题,虽然我确实让播放器在 3 次点击后启动,但更多时候它不会正确显示并且仍然会出现控制台错误。

标签: javascript php html iframe mediaelement


【解决方案1】:

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

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

查看图片

first click

second click

in the third click it works as it should.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多