bitmovin / bitmovinvideo-wordpress

The Bitmovin Wordpress Plugin
GNU General Public License v2.0
4 stars 2 forks source link

Can't load multiple video on same page. #23

Open nad33mahm3d opened 5 years ago

nad33mahm3d commented 5 years ago
add_shortcode("bitmovin_player", "generate_player");
function generate_player($id)
{
    extract(shortcode_atts(array(
        'id' => ''
    ), $id));
    $playerKey = json_decode(get_post_meta($id, '_config_player_key', true));
    if ($playerKey == "")
    {
        return "<pre>No correct api key set in Bitmovin Settings.</pre>";
    }
    $player_version = json_decode(get_post_meta($id, "_config_player_version_url", true));
    wp_register_script('bitmovin_player_core', $player_version);
    wp_enqueue_script('bitmovin_player_core');
    $dash = json_decode(get_post_meta($id, "_config_src_dash", true));
    $hls = json_decode(get_post_meta($id, "_config_src_hls", true));
    $prog = json_decode(get_post_meta($id, "_config_src_prog", true));
    $poster = json_decode(get_post_meta($id, "_config_src_poster", true));
    $html = "<div id='bitmovin-player'></div>\n";
    $html .= "<script type='text/javascript'>\n";
    $html .= "window.onload = function() {\n";
    $html .= "var player = bitmovin.player(\"bitmovin-player\");\n";
    $html .= "var conf = {\n";
    $custom = json_decode(get_post_meta($id, "_config_custom_conf", true));
    if ($custom != "")
    {
        $html .= $custom;
    }
    $html .= "};\n";
    $html .= "conf.key = '" . $playerKey . "';\n";
    $html .= "conf.source = conf.source || {}\n";
    $html .= "conf.source.dash = '" . $dash . "';\n";
    $html .= "conf.source.hls = '" . $hls . "';\n";
    $html .= "conf.source.progressive = '" . $prog . "';\n";
    $html .= "conf.source.poster = '" . $poster . "';\n";
    $html .= "player.setup(conf).then(function(value) {\n";
    $html .= "console.log('Successfully created bitdash player instance');\n";
    $html .= "}, function(reason) {\n";
    $html .= "console.log('Error while creating bitdash player instance');\n";
    $html .= "});\n";
    $html .= "};";
    $html .= "</script>\n";
    return `$html;`
}
nad33mahm3d commented 5 years ago

As in this function you are generating HTML for the player but when users want to show multiple videos on the same page the ID of the player is same so its causing issue.

mhafellner commented 5 years ago

Hi Nadeem,

Thanks for reporting that issue. We have this issue tracked in our product intelligence tool, but currently don't have any plans of implementing an improvement because of scarce resources.

What I do know is that other customers are using a workaround with embedding player instances directly via Javascript instead of using the plugin to use two player instances on the same page. For all other pages you are still good using the plugin.

Hope this helps.

Best, Markus