PHP code example of ride / lib-media

1. Go to this page and download the library: Download ride/lib-media library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ride / lib-media example snippets


abstract protected function parseUrl($url);
abstract protected function loadProperties();

use ride\library\media\factory\UrlMediaItemFactory;
use ride\library\media\factory\VimeoMediaItemFactory;
use ride\library\media\factory\YoutubeMediaItemFactory;
use ride\library\media\MediaFactory;
use ride\library\media\SimpleMediaFactory;
use ride\library\http\client\Client;

function createMediaFactory(Client $httpClient) {
    $youtubeMediaItemFactory = new YoutubeMediaItemFactory($httpClient);
    $youtubeMediaItemFactory->setClientId('client-id');
    
    $vimeoMediaItemFactory = new VimeoMediaItemFactory($httpClient);
    
    $urlMediaItemFactory = new UrlMediaItemFactory($httpClient);

    $mediaFactory = new SimpleMediaFactory($httpClient);
    $mediaFactory->setMediaItemFactory($youtubeMediaItemFactory);
    $mediaFactory->setMediaItemFactory($vimeoMediaItemFactory);
    $mediaFactory->setDefaultMediaItemFactory($urlMediaItemFactory);
    
    return $mediaFactory;
}

function useMediaFactory(MediaFactory $mediaFactory) {
    // create a MediaItem using a URL
    $youtubeMediaItem = $simpleMediaFactory->createMediaItem('https://www.youtube.com/watch?v=njos57IJf-0');
    
    $type = $youtubeMediaItem->getType();
    // youtube
    $id = $youtubeMediaItem->getId();
    // njos57IJf-0
    $title = $youtubeMediaItem->getTitle();
    $description = $youtubeMediaItem->getDescription();
    
    // if you know the type and id, you can fetch it like this
    $youtubeMediaItem = $simpleMediaFactory->getMediaItem($type, $id);
}