/** * Redirect to controls if vlc is running * @param Zend_Controller_Action $controller */ public function gen_beforePageBuild(Zend_Controller_Action $controller) { /* $vlc = X_Vlc::getLastInstance(); if ( $vlc === null ) { X_Debug::i("No vlc instance"); return; } */ $controllerName = $controller->getRequest()->getControllerName(); $actionName = $controller->getRequest()->getActionName(); $query = "{$controllerName}/{$actionName}"; X_Debug::i("Plugin triggered for: {$query}"); //$isRunning = $vlc->isRunning(); $isRunning = X_Streamer::i()->isStreaming(); if (array_search($query, $this->redirectCond_To) !== false && $isRunning) { $controller->getRequest()->setControllerName('controls')->setActionName('control')->setDispatched(false); X_Debug::i("Redirect to controls/control"); } elseif (array_search($query, $this->redirectCond_Away) !== false && !$isRunning) { X_Debug::i("Redirect to index/collections"); $controller->getRequest()->setControllerName('index')->setActionName('collections')->setDispatched(false); } else { X_Debug::i("No redirection: vlc is running? " . ($isRunning ? 'Yes' : 'No')); } }
public function executeAction() { $request = $this->getRequest(); //X_VlcShares_Plugins::broker()->gen_preProviderSelection($this); /* $provider = $request->getParam('p', false); if ( $provider === false || !X_VlcShares_Plugins::broker()->isRegistered($provider) ) { throw new Exception("Invalid provider"); } $location = X_Env::decode($request->getParam('l', '')); */ $pid = $request->getParam('pid', false); $a = $request->getParam('a', false); $engineId = X_Streamer::i()->getStreamingEngineId(); $engine = X_VlcShares_Plugins::helpers()->streamer()->get($engineId); X_VlcShares_Plugins::broker()->preExecute($engine, $pid, $a, $this); X_VlcShares_Plugins::broker()->execute($engine, $pid, $a, $this); X_VlcShares_Plugins::broker()->postExecute($engine, $pid, $a, $this); $pageItems = new X_Page_ItemList_PItem(); $done = new X_Page_Item_PItem('core-opdone', X_Env::_('controls_done')); $done->setCustom('vlc_still_alive', $this->vlc->isRunning())->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(array('controller' => 'controls', 'action' => 'control', 'pid' => null, 'a' => null, 'param' => null), 'default', false); $pageItems->append($done); // links on top $pageItems->merge(X_VlcShares_Plugins::broker()->preGetExecuteItems($pid, $a, $this)); // add separator between play items and options items $separator = new X_Page_Item_PItem('core-separator', X_Env::_('_____options_separator_____')); $separator->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(array('controller' => 'controls', 'action' => 'control', 'pid' => null, 'a' => null, 'param' => null), 'default', false); $pageItems->append($separator); // normal links $pageItems->merge(X_VlcShares_Plugins::broker()->getExecuteItems($pid, $a, $this)); // bottom links $pageItems->merge(X_VlcShares_Plugins::broker()->postGetExecuteItems($pid, $a, $this)); // trigger for page creation X_VlcShares_Plugins::broker()->gen_afterPageBuild($pageItems, $this); }
function removeAction() { $id = $this->getRequest()->getParam('id', false); $csrf = $this->getRequest()->getParam('csrf', false); if (!$id) { throw new Exception("Thread id missing"); } $hash = new Zend_Form_Element_Hash('csrf', array('salt' => __CLASS__)); if (!$hash->isValid($csrf)) { throw new Exception("Invalid token"); } $hash->initCsrfToken(); $thread = X_Threads_Manager::instance()->getMonitor()->getThread($id); // special case for streamer if ($thread->getId() == X_Streamer::THREAD_ID) { X_Debug::i('Special stop'); X_Streamer::i()->stop(); } else { X_Threads_Manager::instance()->halt($thread); } // wait 5 seconds sleep(5); X_Threads_Manager::instance()->getMessenger()->clearQueue($thread); X_Threads_Manager::instance()->getMonitor()->removeThread($thread, true); $this->_helper->flashMessenger(array('type' => 'success', 'text' => X_Env::_('threads_done'))); $this->_helper->redirector('index', 'tmanager'); }
public function streamAction() { $request = $this->getRequest(); X_VlcShares_Plugins::broker()->gen_preProviderSelection($this); $provider = $request->getParam('p', false); if ($provider === false || !X_VlcShares_Plugins::broker()->isRegistered($provider)) { throw new Exception("Invalid provider"); } $location = X_Env::decode($request->getParam('l', '')); $providerObj = X_VlcShares_Plugins::broker()->getPlugins($provider); // if provider is a resolver, i can use new streamer api if (X_VlcShares_Plugins::helpers()->streamer()->isEnabled() && $providerObj instanceof X_VlcShares_Plugins_ResolverInterface) { $url = $providerObj->resolveLocation($location); X_Debug::i("Resolved location: {{$url}}"); // check if url is valid (resolver give null or false on error) if (!$url) { X_Debug::e("Invalid location: {$location}"); throw new Exception("Stream location is invalid: {$url}"); } $engine = X_VlcShares_Plugins::helpers()->streamer()->find($url); X_Debug::i("Streamer engine found: {{$engine->getId()}}"); // automatically set the url as source param in the engine $engine->setSource($url); // NEW APIS // each arg is stored as in a LIFO stack. If i put top priority as first, // low priority args could override it. So i use an inverse priority insertion // register low priority args X_VlcShares_Plugins::broker()->preRegisterStreamerArgs($engine, $url, $provider, $location, $this); // register normal priority args X_VlcShares_Plugins::broker()->registerStreamerArgs($engine, $url, $provider, $location, $this); // register top priority args X_VlcShares_Plugins::broker()->postRegisterStreamerArgs($engine, $url, $provider, $location, $this); X_VlcShares_Plugins::broker()->preStartStreamer($engine, $url, $provider, $location, $this); $results = X_VlcShares_Plugins::broker()->canStartStreamer($engine, $url, $provider, $location, $this); $started = false; if (is_null($results) || !in_array(false, $results)) { X_Debug::i("Starting streamer {{$engine->getId()}}: {$engine}"); $started = true; X_Streamer::i()->start($engine); } else { $pluginId = array_search(false, $results, true); X_Debug::f("Plugin {{$pluginId}} prevented streamer from starting..."); //throw new Exception("Plugin {{$pluginId}} prevented streamer from starting"); } X_VlcShares_Plugins::broker()->postStartStreamer($started, $engine, $url, $provider, $location, $this); } else { // otherwise i'm forced to fallback to old api //{{{ THIS CODE BLOCK WILL IS DEPRECATED AND WILL BE REMOVED IN 0.5.6 or 0.6 //TODO remove in 0.5.6 or 0.6 // each arg is stored as in a LIFO stack. If i put top priority as first, // low priority args could override it. So i use an inverse priority insertion // register low priority args X_VlcShares_Plugins::broker()->preRegisterVlcArgs($this->vlc, $provider, $location, $this); // register normal priority args X_VlcShares_Plugins::broker()->registerVlcArgs($this->vlc, $provider, $location, $this); // register top priority args X_VlcShares_Plugins::broker()->postRegisterVlcArgs($this->vlc, $provider, $location, $this); X_VlcShares_Plugins::broker()->preSpawnVlc($this->vlc, $provider, $location, $this); $this->vlc->spawn(); X_VlcShares_Plugins::broker()->postSpawnVlc($this->vlc, $provider, $location, $this); try { $engine = X_VlcShares_Plugins::helpers()->streamer()->get('vlc'); } catch (Exception $e) { X_Debug::w('No vlc streamer available'); $engine = new X_Streamer_Engine_Vlc($this->vlc); } $url = $this->vlc->getArg('source'); //}}} } $pageItems = new X_Page_ItemList_PItem(); // i can't add here the go to play button // because i don't know the output type // i need to leave this to the plugins, too // i hope that an output manager plugin // will be always enabled // top links $pageItems->merge(X_VlcShares_Plugins::broker()->preGetStreamItems($engine, $url, $provider, $location, $this)); // normal links $pageItems->merge(X_VlcShares_Plugins::broker()->getStreamItems($engine, $url, $provider, $location, $this)); // bottom links $pageItems->merge(X_VlcShares_Plugins::broker()->postGetStreamItems($engine, $url, $provider, $location, $this)); // trigger for page creation X_VlcShares_Plugins::broker()->gen_afterPageBuild($pageItems, $this); }
/** * singleton * @param X_Streamer $newInst * @return X_Streamer */ public static function i(X_Streamer $newInst = null) { if ($newInst) { self::$i = $newInst; } if (is_null(self::$i)) { self::$i = new X_Streamer(); } return self::$i; }
private function _action_stop(X_Streamer_Engine $engine, $param) { X_Streamer::i()->stop(); }