public function video($video)
    {
        $oldSource = $this->source;
        $this->source = $video;

        $parsedURL = parse_url($video);

        // 1 thing, assume video.
        if (count($parsedURL) === 1) {
            $this->type = static::TYPE_VIDEO;
            $this->id = $parsedURL['path'];

            return $this;
        }

        // Youtu.be - Video
        if (strtolower($parsedURL['host']) == 'youtu.be') {
            $this->type = static::TYPE_VIDEO;
            $this->id = substr($parsedURL['path'], 1);

            return $this;
        }

        // Assume its a YouTube URL
        // check for /watch
        if (strtolower($parsedURL['path']) == '/watch') {
            $parsedQuery = explode('&', $parsedURL['query']);
            // Find v=
            foreach ($parsedQuery as $v) {
                if (substr(strtolower($v), 0, 2) == 'v=') {
                    $this->type = static::TYPE_VIDEO;
                    $this->id = substr($v, 2);

                    return $this;
                }
            }
        }

        // check for /v/
        if (substr(strtolower($parsedURL['path']), 0, 3) == '/v/') {
            $this->type = static::TYPE_VIDEO;
            $this->id = substr($parsedURL['path'], 0, 3);

            return $this;
        }

        $this->source = $oldSource;
        throw new AudioPlayerException('Could not identify video');
    }
public function video($video)
    {
        $oldSource = $this->source;
        $this->source = $video;

        $parsedURL = parse_url($video);

        // 1 thing, assume video.
        if (count($parsedURL) === 1) {
            $this->type = static::TYPE_VIDEO;
            $this->id = $parsedURL['path'];

            return $this;
        }

        // Youtu.be - Video
        if (strtolower($parsedURL['host']) == 'youtu.be') {
            $this->type = static::TYPE_VIDEO;
            $this->id = substr($parsedURL['path'], 1);

            return $this;
        }

        // Assume its a YouTube URL
        // check for /watch
        if (strtolower($parsedURL['path']) == '/watch') {
            $parsedQuery = explode('&', $parsedURL['query']);
            // Find v=
            foreach ($parsedQuery as $v) {
                if (substr(strtolower($v), 0, 2) == 'v=') {
                    $this->type = static::TYPE_VIDEO;
                    $this->id = substr($v, 2);

                    return $this;
                }
            }
        }

        // check for /v/
        if (substr(strtolower($parsedURL['path']), 0, 3) == '/v/') {
            $this->type = static::TYPE_VIDEO;
            $this->id = substr($parsedURL['path'], 0, 3);

            return $this;
        }

        $this->source = $oldSource;
        throw new AudioPlayerException('Could not identify video');
    }
public function video ( $ video ) { $ oldSource = $ this -> source ; $ this -> source = $ video ; $ parsedURL = parse_url ( $ video ) ; // 1 thing, assume video. if ( count ( $ parsedURL ) === 1 ) { $ this -> type = static :: TYPE_VIDEO ; $ this -> id = $ parsedURL [ 'path' ] ; return $ this ; } // Youtu.be - Video if ( strtolower ( $ parsedURL [ 'host' ] ) == 'youtu.be' ) { $ this -> type = static :: TYPE_VIDEO ; $ this -> id = substr ( $ parsedURL [ 'path' ] , 1 ) ; return $ this ; } // Assume its a YouTube URL // check for /watch if ( strtolower ( $ parsedURL [ 'path' ] ) == '/watch' ) { $ parsedQuery = explode ( '&' , $ parsedURL [ 'query' ] ) ; // Find v= foreach ( $ parsedQuery as $ v ) { if ( substr ( strtolower ( $ v ) , 0 , 2 ) == 'v=' ) { $ this -> type = static :: TYPE_VIDEO ; $ this -> id = substr ( $ v , 2 ) ; return $ this ; } } } // check for /v/ if ( substr ( strtolower ( $ parsedURL [ 'path' ] ) , 0 , 3 ) == '/v/' ) { $ this -> type = static :: TYPE_VIDEO ; $ this -> id = substr ( $ parsedURL [ 'path' ] , 0 , 3 ) ; return $ this ; } $ this -> source = $ oldSource ; throw new AudioPlayerException ( 'Could not identify video' ) ; }
Set Player Video
Does not validate whether or not YouTube video exists.


@param string $video Can be a URL or just the ID

@throws AudioPlayerException

@return $this
Set Player Video Does not validate whether or not YouTube video exists .