PHP code example of rajendra / youtube-progress

1. Go to this page and download the library: Download rajendra/youtube-progress 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/ */

    

rajendra / youtube-progress example snippets


// config/youtube-progress.php
return [
    'save_interval'          => 10000,     // ms between autosaves
    'completion_percentage'  => 95,        // % unique watched to complete
    'storage_prefix'         => 'rajendra_progress_',
    'auto_resume'            => true,
    'auto_load_api'          => true,
    'debug'                  => false,

    // Anti-cheat (new in v1.0.2)
    'prevent_forward_seek'   => true,
    'maximum_allowed_speed'  => 2,
    'seek_tolerance'         => 1.5,
    'toast_duration'         => 3000,
    'toast_message'          => 'You must watch this part before continuing.',

    // Dimensions
    'default_width'          => '100%',
    'default_height'         => '480',
];

{!! youtube_progress('dQw4w9WgXcQ') !!}

{!! youtube_progress('dQw4w9WgXcQ', ['height' => 360, 'prevent-seek' => true]) !!}

use Rajendra\YoutubeProgress\Facades\YoutubeProgress;

$videoId = YoutubeProgress::resolveVideoId('https://youtu.be/dQw4w9WgXcQ');
$key = YoutubeProgress::storageKey($videoId);
bash
php artisan vendor:publish --tag=youtube-progress
bash
php artisan vendor:publish --tag=youtube-progress-config
php artisan vendor:publish --tag=youtube-progress-assets
php artisan vendor:publish --tag=youtube-progress-views
blade
<x-youtube-progress
    video="dQw4w9WgXcQ"
    on-complete="myCompleteHandler"
    on-seek-blocked="myBlockedHandler"
    on-progress="myProgressHandler"
/>

<script>
    function myCompleteHandler(detail) {
        // detail contains: videoId, percentage, segments, completed, etc.
        markLessonComplete(detail.videoId);
    }

    function myBlockedHandler(detail) {
        // detail contains: from, attempted, snappedTo
        showWarning('You skipped ahead!');
    }

    function myProgressHandler(detail) {
        // Fires on every save — throttle if needed
        updateSidebarProgress(detail.videoId, detail.percentage);
    }
</script>