コード例 #1
0
function yss_generate_player($player, $video, $width, $height)
{
    global $codes, $yss_plugins, $yss_master_counter;
    $yss_master_counter++;
    $distribution = $video->distribution;
    $distribution = json_decode($distribution);
    $stream = FALSE;
    $url = '';
    $valid = time() + YSS_EXPIRE_TIME_LIMIT;
    $return = '';
    $yss_cloudfront = new CloudFront();
    if (isset($distribution->streaming) && $distribution->streaming) {
        $streamer = $distribution->streaming;
        // streamer
        // resource magic
        // FLV?
        $resource = str_replace('.flv', '', $video->resource_path);
        $url = $yss_cloudfront->generateSecureUrl($resource, $valid);
        // streamer
        $streamer = 'rtmp://' . $streamer . '/cfx/st';
        // non standard code required
        switch ($player) {
            case 'custom':
                $url = yss_generate_yss_url($video, FALSE);
                $return = yss_custom_player($url, $height, $width, $streamer);
                break;
            case 'fv-wordpress-flowplayer':
                if (strpos($video->resource_path, '.flv')) {
                    $url = str_replace(array('=', '&'), array('%3D', '%26'), $url);
                    $return = '
<div id="streams_' . str_replace('.', '_', $resource) . '" style="display:block;width:' . $width . 'px;height:' . $height . 'px;"></div>
<script type="text/javascript">' . "\nflowplayer('streams_" . str_replace('.', '_', $resource) . "', '" . PLAYER . " ', {\n\tclip:  {\n\t\tautoPlay: false,\n\t\tautoBuffering: true,\n\t\t\n\t\turl: '" . $url . "',\n\t\tprovider: 'rtmp'\n\t},\n\tplugins: {\n\t\trtmp: {\n\t\t\turl: '" . YSS_RESOURCES . "/flowplayer.rtmp-3.2.3.swf',\n\t\t\tnetConnectionUrl: '" . $streamer . "'\n\t\t}\n\t}\n});\n</script>";
                } else {
                    echo 'YSS does not support non FLV files in a streaming distribution under FlowPlayer. It just does not work!';
                }
                break;
            case 'jw-player-plugin-for-wordpress':
                if (isset($distribution->download) && $distribution->download) {
                    $download = $distribution->download;
                    $durl = 'https://' . $download . '/' . $video->resource_path;
                    $durl = $yss_cloudfront->generateSecureUrl($durl, $valid);
                } else {
                    $durl = yss_generate_yss_url($video, FALSE);
                }
                $return = '
<div id="mediaspace_' . str_replace('.', '_', $resource) . '_' . $yss_master_counter . '">This text will be replaced</div>
<script type="text/javascript">' . "\n\tjwplayer('mediaspace_" . str_replace('.', '_', $resource) . '_' . $yss_master_counter . "').setup({\n\t\tflashplayer:\t'" . JWPLAYER_FILES_URL . "/player/player.swf',\n\t\tcontrolbar:\t\t'bottom',\n\t\twidth:\t\t\t'" . $width . "',\n\t\theight:\t\t\t'" . $height . "',\n\t\tconfig:\t\t\t'" . JWPLAYER_FILES_URL . '/configs/' . get_option('jwplayermodule_default') . ".xml',\n\t\tmodes: [\n\t\t\t{\n\t\t\t\ttype: 'flash',\n\t\t\t\tsrc: '" . JWPLAYER_FILES_URL . "/player/player.swf',\n\t\t\t\tconfig: {\n\t\t\t\t\tfile: '" . $url . "',\n\t\t\t\t\tstreamer: '" . $streamer . "',\n\t\t\t\t\tprovider: 'rtmp'\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: 'html5',\n\t\t\t\tconfig: {\n\t\t\t\t\tfile: '" . $durl . "'\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: 'flash',\n\t\t\t\tsrc: '" . JWPLAYER_FILES_URL . "/player/player.swf',\n\t\t\t\tconfig: {\n\t\t\t\t\tfile: '" . $durl . "'\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t});\n</script>\n";
                break;
            default:
                $return = '<p>' . __('No Player Selected', 'yss') . '</p>';
        }
    } else {
        if (isset($distribution->download) && $distribution->download) {
            $download = $distribution->download;
            // download dist
            $url = 'https://' . $download . '/' . $video->resource_path;
            $url = $yss_cloudfront->generateSecureUrl($url, $valid);
            if ($yss_plugins[$player]['encode']) {
                $url = explode('?', $url);
                $url[1] = urlencode($url[1]);
                $url = implode('?', $url);
            }
            $return = sprintf($codes[$player], $url, $width, $height);
        } else {
            // s3
            if ($player == 'custom') {
                $url = yss_generate_yss_url($video, FALSE);
                $return = yss_custom_player($url, $height, $width);
            } else {
                $url = yss_generate_yss_url($video);
                $return = sprintf($codes[$player], $url, $width, $height);
            }
        }
    }
    return $return;
}