flutter_youtube_video 1.0.1

SDKflutter
Platformandroidioswindowsmacosweb

Flutter package to play Youtube videos using the InAppWebView plugin.

Flutter YouTube Video

A Flutter package for playing YouTube videos using the InAppWebView plugin. This package provides a customizable YouTube player widget with playback controls, fullscreen support, and callback events. It also includes a utility method to extract video IDs from YouTube URLs.

Features

  • Play YouTube videos using InAppWebView
  • Extract YouTube video ID from full URLs using extractId
  • Customizable player settings:
    • Auto-play
    • Looping
    • Muted
    • Show/hide controls
    • Start time configuration
  • Fullscreen support
  • Background color customization
  • Callback events for:
    • Player ready
    • Play
    • Pause
    • Finish
    • Seek
    • Time update

Installation

Add the following to your pubspec.yaml file:

dependencies:
  flutter_youtube_video: ^latest-version

Then run:

flutter pub get

Usage

Basic Usage

import 'package:flutter/material.dart';
import 'package:flutter_youtube_video/flutter_youtube_video.dart';

class MyYouTubePlayer extends StatelessWidget {
  const MyYouTubePlayer({super.key});

  @override
  Widget build(BuildContext context) {
    return FlutterYouTubePlayer(
      videoId: '12345678', // Replace with your YouTube video ID
    );
  }
}

Advanced Usage

FlutterYouTubePlayer(
  videoId: 'dQw4w9WgXcQ',
  isAutoPlay: true,
  isLooping: false,
  isMuted: false,
  showControls: true,
  startTime: 15.0,
  backgroundColor: Colors.black,
  onReady: (totalDuration, currentDuration) {
    debugPrint('Player ready: Total duration: $totalDuration');
  },
  onPlay: (totalDuration, currentDuration) {
    debugPrint('Video playing at $currentDuration');
  },
  onPause: (totalDuration, currentDuration) {
    debugPrint('Video paused at $currentDuration');
  },
  onFinish: (totalDuration, currentDuration) {
    debugPrint('Video finished');
  },
  onSeek: (totalDuration, currentDuration) {
    debugPrint('Seeked to $currentDuration');
  },
  onTimeUpdate: (totalDuration, currentDuration) {
    debugPrint('Time updated: $currentDuration');
  },
);

Extracting Video ID from a YouTube URL

import 'package:flutter_youtube_video/flutter_youtube_video.dart';

void main() {
  final url = 'https://www.youtube.com/watch?v=1234567';
  final id = extractId(url); // returns '1234567'
  print('Video ID: $id');
}

Supported formats: • https://www.youtube.com/watch?v=VIDEO_IDhttps://youtu.be/VIDEO_IDhttps://youtube.com/embed/VIDEO_ID

Parameters

ParameterTypeDefaultDescription
videoIdStringrequiredThe YouTube video ID
isAutoPlayboolfalseWhether to auto-play the video
isLoopingboolfalseWhether to loop the video
isMutedboolfalseWhether to mute the video
showControlsbooltrueWhether to show video controls
startTimedouble0.0Start time in seconds
backgroundColorColorColors.blackBackground color of the player
onReadyDurationCallback?nullCalled when the video is ready
onPlayDurationCallback?nullCalled when the video starts playing
onPauseDurationCallback?nullCalled when the video is paused
onFinishDurationCallback?nullCalled when the video finishes
onSeekDurationCallback?nullCalled when seeking in the video
onTimeUpdateDurationCallback?nullCalled when the video time updates

Example

See the example directory for a complete example application.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.# flutter_youtube_video