libretime/legacy/application/forms/Player.php

87 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2015-02-12 20:08:06 +01:00
<?php
2021-10-11 16:10:47 +02:00
define('OPUS', 'opus');
2015-04-07 23:49:21 +02:00
2015-04-08 20:01:57 +02:00
class Application_Form_Player extends Zend_Form_SubForm
2015-02-12 20:08:06 +01:00
{
public function init()
{
2021-10-11 16:10:47 +02:00
$this->setDecorators([
['ViewScript', ['viewScript' => 'form/player.phtml']],
]);
2015-02-12 20:08:06 +01:00
2015-04-09 20:22:50 +02:00
$title = new Zend_Form_Element_Text('player_title');
$title->setValue(_('Now Playing'));
$title->setLabel(_('Title:'));
2021-10-11 16:10:47 +02:00
$title->setDecorators([
2015-04-09 15:43:15 +02:00
'ViewHelper',
'Errors',
2021-10-11 16:10:47 +02:00
'Label',
]);
$title->addDecorator('Label', ['class' => 'player-title']);
2015-04-09 15:43:15 +02:00
$this->addElement($title);
2015-02-12 20:08:06 +01:00
$streamMode = new Zend_Form_Element_Radio('player_stream_mode');
$streamMode->setLabel(_('Select Stream:'));
$streamMode->setMultiOptions(
2021-10-11 16:10:47 +02:00
[
'auto' => _('Auto detect the most appropriate stream to use.'),
'manual' => _('Select a stream:'),
]
);
2021-10-11 16:10:47 +02:00
$streamMode->setValue('auto');
$this->addElement($streamMode);
$streamURL = new Zend_Form_Element_Radio('player_stream_url');
$opusStreamCount = 0;
2021-10-11 16:10:47 +02:00
$urlOptions = [];
foreach (Application_Model_StreamSetting::getEnabledStreamData() as $stream => $data) {
$urlOptions[$stream] = strtoupper($data['codec']) . ' - ' . $data['bitrate'] . 'kbps';
if ($data['mobile']) {
$urlOptions[$stream] .= _(' - Mobile friendly');
}
2021-10-11 16:10:47 +02:00
if ($data['codec'] == OPUS) {
++$opusStreamCount;
$urlOptions[$stream] .= _(' - The player does not support Opus streams.');
}
}
$streamURL->setMultiOptions(
$urlOptions
);
2015-04-07 23:49:21 +02:00
// Set default value to the first non-opus stream we find
foreach ($urlOptions as $o => $v) {
2015-04-07 23:49:21 +02:00
if (strpos(strtolower($v), OPUS) !== false) {
continue;
}
2021-10-11 16:10:47 +02:00
$streamURL->setValue($o);
break;
}
$streamURL->setAttrib('numberOfEnabledStreams', count($urlOptions) - $opusStreamCount);
2015-04-08 20:01:57 +02:00
$streamURL->removeDecorator('label');
$this->addElement($streamURL);
2015-04-09 15:43:15 +02:00
$embedSrc = new Zend_Form_Element_Textarea('player_embed_src');
2021-10-11 16:10:47 +02:00
$embedSrc->setAttrib('readonly', 'readonly');
$embedSrc->setAttrib('class', 'embed-player-text-box');
2015-04-09 15:43:15 +02:00
$embedSrc->setAttrib('cols', '40')
->setAttrib('rows', '4');
2021-10-11 16:10:47 +02:00
$embedSrc->setLabel(_('Embeddable code:'));
2015-04-09 20:22:50 +02:00
$embedSrc->setDescription(_("Copy this code and paste it into your website's HTML to embed the player in your site."));
$embedSrc->setValue('<iframe frameborder="0" width="280" height="216" src="' . Config::getPublicUrl() . 'embed/player?stream=auto&title=Now Playing"></iframe>');
$this->addElement($embedSrc);
$previewLabel = new Zend_Form_Element_Text('player_preview_label');
2021-10-11 16:10:47 +02:00
$previewLabel->setLabel(_('Preview:'));
$previewLabel->setDecorators([
'ViewHelper',
'Errors',
2021-10-11 16:10:47 +02:00
'Label',
]);
$previewLabel->addDecorator('Label', ['class' => 'preview-label']);
$this->addElement($previewLabel);
2015-02-12 20:08:06 +01:00
}
}