jcisio / media-wrapper
2.0
2017-11-08 14:54 UTC
Requires
- php: >=5.3.5
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: >=3.7
README
简介
- 作者:Hai-Nam Nguyen (jcisio)
- 主页: https://github.com/jcisio/MediaWrapper
- 需要 PHP 5.6 或更高版本
- 它被如 Internet Sources field 或 Content Attachment 这样的 Drupal 模块使用。
快速开始
示例
include 'MediaWrapper/MediaWrapper.php';
$m = MediaWrapper::getInstance()->getWrapper('http://www.youtube.com/watch?v=vyfzw09jjEo');
// Print the thumbnail.
print $m->thumbnail();
// Print the full player.
print $m->player();
// Set default player options.
$m->player_options(array('width' => '200', 'height' => '100'));
// Print the full player again with new default options.
print $m->player();
// Override default options and print the full player.
print $m->player(array('height' => '120'));
使用 PHPUnit 测试
phpunit
或者如果你没有 PHPUnit
Composer install --dev
vendor/phpunit/phpunit/phpunit
用例
MediaWrapper 可扩展。
编写自己的包装器
你可以查看 MediaWrapper/Wrapper 文件夹中的示例。一旦你有了自己的包装器,包含该文件并使用以下方式注册该包装器:
MediaWrapper::getInstance()->register();
重写输出
你可以扩展一个包装器,保留模式并重写 player() 函数。不要忘记注销旧包装器,以确保只有你的包装器处理该模式。
响应式播放器
在大多数情况下,MediaWrapper 使用每个服务提供的默认播放器。为了使播放器响应式(例如宽度 = 100%),你可以使用 CSS 使 iframe 响应式。有很多教程可供参考。
另一种解决方案是使用出色的微小 Fitvids JS jQuery 插件来使所有视频响应式。它会处理你的 CSS。