ktk_mediaserve/modules/Player.php

40 lines
1.3 KiB
PHP

<?php
namespace ktk\MediaServe;
class Player {
static public function onInit() {
if (!MediaServe::getData('player_file')) {
MediaServe::storeData('player_file', "");
MediaServe::storeData('player_seek', 0);
MediaServe::storeData('player_play', FALSE);
}
}
static public function onProcess() {
}
static public function onRender() {
$codecs = MediaServe::loadConf('codecs');
$filename = MediaServe::getData('player_file');
$filetype = $codecs[pathinfo($filename, PATHINFO_EXTENSION)];
if (!$filetype) {
$filetype = 'application/octet-stream';
}
echo '<div id="ktk_MediaServe_Player">',PHP_EOL;
echo '<audio src="',MediaServe::getData('player_file'),'" type="',$filetype,'" preload="metadata" ',(MediaServe::getData('player_play') == TRUE ? 'autoplay' : ''),' controls="controls">',PHP_EOL;
echo 'TODO: Fallback to Flash or something similar here, I suppose',PHP_EOL;
echo '</audio>',PHP_EOL;
echo '</div>',PHP_EOL;
}
static public function onClose() {
// if we've started playing, do not auto play again
if (MediaServe::getData('player_play') == TRUE) {
MediaServe::storeData('player_play', FALSE);
}
}
static public function openFile($file) {
MediaServe::storeData('player_file', $file);
MediaServe::storeData('player_play', TRUE);
}
}
?>