Пример #1
0
 public function list_supported_urls(array $urls, array $options = array())
 {
     $extensions = $this->get_supported_extensions();
     $result = array();
     foreach ($urls as $url) {
         $ext = core_media::get_extension($url);
         if (in_array($ext, $extensions)) {
             if ($ext === 'ogg' || $ext === 'oga') {
                 // Formats .ogg and .oga are not supported in IE, Edge, or Safari.
                 if (core_useragent::is_ie() || core_useragent::is_edge() || core_useragent::is_safari()) {
                     continue;
                 }
             } else {
                 // Formats .aac, .mp3, and .m4a are not supported in Opera.
                 if (core_useragent::is_opera()) {
                     continue;
                 }
                 // Formats .mp3 and .m4a were not reliably supported in Firefox before 27.
                 // https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats
                 // has the details. .aac is still not supported.
                 if (core_useragent::is_firefox() && ($ext === 'aac' || !core_useragent::check_firefox_version(27))) {
                     continue;
                 }
             }
             // Old Android versions (pre 2.3.3) 'support' audio tag but no codecs.
             if (core_useragent::is_webkit_android() && !core_useragent::is_webkit_android('533.1')) {
                 continue;
             }
             $result[] = $url;
         }
     }
     return $result;
 }
Пример #2
0
    public function embed($urls, $name, $width, $height, $options)
    {
        if (array_key_exists(core_media_manager::OPTION_ORIGINAL_TEXT, $options) && preg_match('/^<(video|audio)\\b/i', $options[core_media_manager::OPTION_ORIGINAL_TEXT], $matches)) {
            // We already had media tag, do nothing here.
            return $options[core_media_manager::OPTION_ORIGINAL_TEXT];
        }
        // Special handling to make videos play on Android devices pre 2.3.
        // Note: I tested and 2.3.3 (in emulator) works without, is 533.1 webkit.
        $oldandroid = core_useragent::is_webkit_android() && !core_useragent::check_webkit_android_version('533.1');
        // Build array of source tags.
        $sources = array();
        foreach ($urls as $url) {
            $mimetype = core_media_manager::instance()->get_mimetype($url);
            $source = html_writer::empty_tag('source', array('src' => $url, 'type' => $mimetype));
            if ($mimetype === 'video/mp4') {
                if ($oldandroid) {
                    // Old Android fails if you specify the type param.
                    $source = html_writer::empty_tag('source', array('src' => $url));
                }
                // Better add m4v as first source, it might be a bit more
                // compatible with problematic browsers.
                array_unshift($sources, $source);
            } else {
                $sources[] = $source;
            }
        }
        $sources = implode("\n", $sources);
        $title = $this->get_name($name, $urls);
        // Escape title but prevent double escaping.
        $title = s(preg_replace(['/&amp;/', '/&gt;/', '/&lt;/'], ['&', '>', '<'], $title));
        self::pick_video_size($width, $height);
        if (!$height) {
            // Let browser choose height automatically.
            $size = "width=\"{$width}\"";
        } else {
            $size = "width=\"{$width}\" height=\"{$height}\"";
        }
        $sillyscript = '';
        $idtag = '';
        if ($oldandroid) {
            // Old Android does not support 'controls' option.
            $id = 'core_media_html5v_' . md5(time() . '_' . rand());
            $idtag = 'id="' . $id . '"';
            $sillyscript = <<<OET
<script type="text/javascript">
document.getElementById('{$id}').addEventListener('click', function() {
    this.play();
}, false);
</script>
OET;
        }
        // We don't want fallback to another player because list_supported_urls() is already smart.
        // Otherwise we could end up with nested <video> tags. Fallback to link only.
        $fallback = self::LINKPLACEHOLDER;
        return <<<OET
<span class="mediaplugin mediaplugin_html5video">
<video {$idtag} controls="true" {$size} preload="metadata" title="{$title}">
    {$sources}
    {$fallback}
</video>
{$sillyscript}
</span>
OET;
    }
Пример #3
0
 public function list_supported_urls(array $urls, array $options = array())
 {
     $extensions = $this->get_supported_extensions();
     $result = array();
     foreach ($urls as $url) {
         $ext = core_media::get_extension($url);
         if (in_array($ext, $extensions)) {
             if ($ext === 'ogg' || $ext === 'oga') {
                 // Formats .ogg and .oga are not supported in IE or Safari.
                 if (core_useragent::is_ie() || core_useragent::is_safari()) {
                     continue;
                 }
             } else {
                 // Formats .aac, .mp3, and .m4a are not supported in Firefox or Opera.
                 if (core_useragent::is_firefox() || core_useragent::is_opera()) {
                     continue;
                 }
             }
             // Old Android versions (pre 2.3.3) 'support' audio tag but no codecs.
             if (core_useragent::is_webkit_android() && !core_useragent::is_webkit_android('533.1')) {
                 continue;
             }
             $result[] = $url;
         }
     }
     return $result;
 }
Пример #4
0
 /**
  * @dataProvider user_agents_providers
  */
 public function test_useragent_webkit_android($useragent, $tests)
 {
     // Setup the core_useragent instance.
     core_useragent::instance(true, $useragent);
     if (isset($tests['is_webkit_android']) && $tests['is_webkit_android']) {
         $this->assertTrue(core_useragent::is_webkit_android(), "Browser was not identified as an Android webkit browser");
         $this->assertTrue(core_useragent::check_webkit_android_version());
     } else {
         $this->assertFalse(core_useragent::is_webkit_android(), "Browser was incorrectly identified as an Android webkit browser");
         $this->assertFalse(core_useragent::check_webkit_android_version());
     }
     $versions = array('525' => false, '527' => false, '590' => false);
     if (isset($tests['check_webkit_android_version'])) {
         // The test provider has overwritten some of the above checks.
         // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
         $versions = $tests['check_webkit_android_version'] + $versions;
     }
     foreach ($versions as $version => $result) {
         $this->assertEquals($result, core_useragent::check_webkit_android_version($version), "Version incorrectly determined for Android webkit version '{$version}'");
     }
 }