This plugin provides seamless integration between Moodle and Cloudflare Stream, automatically uploading video files to Cloudflare's video streaming service and replacing them with optimized Stream players.
- Automatic Video Upload: Videos uploaded to Moodle are automatically sent to Cloudflare Stream
- Seamless Player Integration: Stream videos are displayed using Cloudflare's optimized video player
- Background Processing: Video uploads happen asynchronously using Moodle's task system
- Configurable Settings: Full control over player behavior and upload options
- Multiple Video Formats: Supports MP4, AVI, MOV, WMV, WebM, and OGG formats
- Optional File Cleanup: Choose whether to keep or delete original files after Stream upload
- Moodle 4.5 or later
- Cloudflare account with Stream service enabled
- PHP cURL extension
- Valid Cloudflare Stream API credentials
-
Download or clone this plugin to your Moodle installation:
cd /path/to/moodle/local/ git clone https://github.com/yourusername/moodle-local_cloudflarestream.git cloudflarestream -
Run the Moodle upgrade process:
php admin/cli/upgrade.php
Or visit your Moodle site as an administrator and follow the upgrade prompts.
-
Navigate to Site Administration > Plugins > Local plugins > Cloudflare Stream Integration
-
Configure the following settings:
- Account ID: Your Cloudflare Account ID (found in your Cloudflare dashboard)
- API Token: Your Cloudflare Stream API Token with Stream:Edit permission
- Enable Cloudflare Stream: Toggle to enable/disable the integration
- Delete original file: Choose whether to delete the original video file after successful Stream upload
- Show player controls: Display video player controls
- Auto-play videos: Automatically start playing videos when loaded
- Loop videos: Loop videos when they finish playing
-
Account ID:
- Log into your Cloudflare dashboard
- Select your domain
- Account ID is shown in the right sidebar
-
API Token:
- Go to My Profile > API Tokens
- Click Create Token
- Use the Custom token template
- Set permissions:
Zone:Stream:Edit - Add your account as a resource
- Click Continue to summary and Create Token
- File Upload Detection: When a video file is uploaded to Moodle, the plugin detects it via event observers
- Background Upload: An asynchronous task uploads the video to Cloudflare Stream
- Database Tracking: The plugin maintains a mapping between Moodle files and Stream video IDs
- Player Replacement: When videos are displayed, they're automatically replaced with Stream players
- Status Updates: Video processing status is tracked and updated from the Stream API
- MP4 (video/mp4)
- MPEG (video/mpeg)
- QuickTime (video/quicktime)
- AVI (video/x-msvideo)
- WMV (video/x-ms-wmv)
- WebM (video/webm)
- OGG (video/ogg)
The plugin creates one database table:
local_cloudflarestream_videos: Maps Moodle file IDs to Cloudflare Stream video IDs and stores metadata
# Unit tests
php admin/tool/phpunit/cli/util.php --buildconfig
php admin/tool/phpunit/cli/util.php --install
vendor/bin/phpunit local/cloudflarestream/tests/
# Behat tests
php admin/tool/behat/cli/init.php
vendor/bin/behat --config /path/to/moodle/behatdata/behat/behat.yml --tags="@local_cloudflarestream"\local_cloudflarestream\api: Handles all Cloudflare Stream API interactions\local_cloudflarestream\video_manager: Manages video records and player generation\local_cloudflarestream\observer: Event observer for file uploads\local_cloudflarestream\task\upload_video: Asynchronous upload task
- Check that the plugin is enabled in settings
- Verify your Cloudflare credentials are correct
- Check the Moodle task queue: Site Administration > Server > Tasks > Scheduled tasks
- Look for error messages in the Moodle logs
- Ensure videos have finished processing on Cloudflare Stream
- Check browser console for JavaScript errors
- Verify your Cloudflare account ID is correct
Common API errors and solutions:
- 401 Unauthorized: Check your API token has the correct permissions
- 403 Forbidden: Verify the account ID matches your API token
- 413 Payload Too Large: Video file exceeds Cloudflare's size limits
- 429 Too Many Requests: API rate limit exceeded, uploads will retry automatically
- API tokens are stored securely in Moodle's config system
- File uploads are validated for video formats only
- Signed URLs can be generated for private video access
- All API communications use HTTPS
For issues and questions:
- Check the Moodle logs for error messages
- Verify your Cloudflare Stream configuration
- Review the troubleshooting section above
- Submit issues to the project repository
This plugin is licensed under the GNU General Public License v3.0 or later.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
- Initial release
- Automatic video upload to Cloudflare Stream
- Configurable player settings
- Background processing with task queue
- Comprehensive test suite
- Behat integration tests