PHP code example of tourze / aliyun-vod-bundle

1. Go to this page and download the library: Download tourze/aliyun-vod-bundle 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/ */

    

tourze / aliyun-vod-bundle example snippets


return [
    // ...
    Tourze\AliyunVodBundle\AliyunVodBundle::class => ['all' => true],
];

use Tourze\AliyunVodBundle\Service\VideoUploadService;

class VideoController
{
    public function __construct(
        private VideoUploadService $videoUploadService
    ) {}

    public function upload(Request $request)
    {
        $uploadedFile = $request->files->get('video');
        $config = $this->getVodConfig(); // Get your VOD configuration
        
        $result = $this->videoUploadService->uploadVideo(
            $uploadedFile,
            $config,
            'My Video Title',
            'Video description'
        );
        
        return $this->json($result);
    }
}

use Tourze\AliyunVodBundle\Service\PlayAuthService;

class VideoController
{
    public function __construct(
        private PlayAuthService $playAuthService
    ) {}

    public function getPlayAuth(string $videoId)
    {
        $config = $this->getVodConfig();
        $playAuth = $this->playAuthService->getPlayAuth($videoId, $config);
        
        return $this->json(['playAuth' => $playAuth]);
    }
}

use Tourze\AliyunVodBundle\Service\VideoManageService;
use Tourze\AliyunVodBundle\Service\TranscodeService;

class AdvancedVideoController
{
    public function __construct(
        private VideoManageService $videoManageService,
        private TranscodeService $transcodeService
    ) {}

    public function processVideo(string $videoId)
    {
        $config = $this->getVodConfig();
        
        // Update video metadata
        $this->videoManageService->updateVideoInfo(
            $videoId,
            $config,
            'Updated Title',
            'Updated Description',
            ['tag1', 'tag2']
        );
        
        // Start transcoding with custom template
        $transcodeTask = $this->transcodeService->submitTranscodeJobs(
            $videoId,
            $config,
            'template_group_id'
        );
        
        return $this->json($transcodeTask);
    }
}

use Tourze\AliyunVodBundle\Service\StatisticsService;

class AnalyticsController
{
    public function __construct(
        private StatisticsService $statisticsService
    ) {}

    public function getVideoAnalytics(string $videoId)
    {
        $video = $this->getVideo($videoId);
        
        // Get comprehensive video statistics
        $stats = $this->statisticsService->getVideoPlayStats($video);
        
        // Get completion rate
        $completionRate = $this->statisticsService->getVideoCompletionRate($video);
        
        // Get user behavior analysis
        $userBehavior = $this->statisticsService->getUserPlayBehavior($ipAddress);
        
        return $this->json([
            'stats' => $stats,
            'completion_rate' => $completionRate,
            'user_behavior' => $userBehavior
        ]);
    }
}

use Tourze\AliyunVodBundle\Repository\VideoRepository;

class BatchVideoController
{
    public function __construct(
        private VideoRepository $videoRepository,
        private VideoManageService $videoManageService
    ) {}

    public function batchUpdateStatus(array $videoIds, string $status)
    {
        $config = $this->getVodConfig();
        $results = [];
        
        foreach ($videoIds as $videoId) {
            try {
                $result = $this->videoManageService->updateVideoStatus(
                    $videoId,
                    $config,
                    $status
                );
                $results[] = ['video_id' => $videoId, 'success' => true];
            } catch (\Exception $e) {
                $results[] = [
                    'video_id' => $videoId,
                    'success' => false,
                    'error' => $e->getMessage()
                ];
            }
        }
        
        return $this->json($results);
    }
}

use Symfony\Component\Security\Http\Attribute\IsGranted;

class VideoController
{
    #[IsGranted('ROLE_VIDEO_ADMIN')]
    public function manageVideos() { /* ... */ }
    
    #[IsGranted('ROLE_VIDEO_UPLOAD')]
    public function uploadVideo() { /* ... */ }
    
    #[IsGranted('ROLE_STATISTICS_VIEW')]
    public function viewStatistics() { /* ... */ }
}