Youtube Video Stream Url Using Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

Youtube video streaming integration is explained in this part of the tutorials we play videos directly from the youtube with the help of a youtube video URL.Youtube is the highly used video search engine from google almost everyone have experienced the usage and when there is requirement to display videos on mobile app youtube is the best option because it manages all the hassle of storing the video and playing it.We integrate youtube and play a video proving the detailed source code of enabling youtube api in google api console.

Youtube Video Stream Url Using Flutter Android App

Youtube Video Stream Url 
Step 1 
We cannot directly remove the time stamp from Youtube Video Stream Url but using the intl.dart package we can easily filter the date stamp from time stamp. So open your flutter project’s pubspec.yaml in code .

dependencies:
  flutter:
    sdk: flutter
  flutter_youtube: ^2.0.0

Step 2
After done saving the pubspec.yaml file, Open your flutter project root folder in Command Prompt or Terminal and execute flutter pub get command.

flutter pub get



Complete Code For Youtube Video Stream Url  In Flutter
main.dart
import 'package:flutter/material.dart';
import 'package:flutter_youtube/flutter_youtube.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  TextEditingController textEditingControllerUrl = new TextEditingController();
  @override
  initState() {
    super.initState();
  }
  void playYoutubeVideoEdit() {
    FlutterYoutube.playYoutubeVideoByUrl(
      apiKey: "You Api Key Here",
      videoUrl: textEditingControllerUrl.text,
    );
  }
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      debugShowCheckedModeBanner: false,
      home: new Scaffold(
        appBar: new AppBar(
          backgroundColor: Colors.orange,
          title: new Text('Youtube Player'),
        ),
        body: Center(
          child: Container(
            margin: EdgeInsets.only(left: 16.0),
            child: TextFormField(
              controller: textEditingControllerUrl,
              decoration: InputDecoration(
                  hintText: 'Youtube url here...',
                  filled: true,
                  prefixIcon: Icon(
                    Icons.video_library,
                    color: Colors.red[900],
                    size: 28.0,
                  ),
                  suffixIcon: IconButton(
                      icon: Icon(Icons.play_arrow),
                      onPressed: () {
                        playYoutubeVideoEdit();
                      })),
            ),
          ),
        ),
      ),
    );
  }
}

Related Post