VOOZH about

URL: https://www.geeksforgeeks.org/flutter/flutter-handling-videos/

⇱ Flutter - Handling videos - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Flutter - Handling videos

Last Updated : 23 Jul, 2025

A video is an important form of media that can be used in the application. In Flutter, videos are handled through the use of video_player plugin. This performs tasks like playing a video, pausing a video, or muting the video. It can be used to play videos from the internet or the videos stored in the assets of the application.

In this article, we will explore the same in detail through an example application.

Steps to build a simple app that can play videos:

Step 1 : Adding video_player plugin

To add the video_player plugin to the flutter app, open the pubspec.yaml file and add the video_palyer dependency as shown below:

video_player: ^2.9.3

Step 2 : Giving Permissions

To stream videos from the internet the app will be needing a correct set of configurations. Depending upon the OS of the device we can set the permissions as shown below.

Android:

For Android devices, the permission to stream videos from the internet can be added by going into the Androidmanifest.xml file at 

<project root>/android/app/src/main/AndroidManifest.xml. And add the below lines write after the <application> definition :

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
Definition of the Flutter Application....
</application>

<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

iOS:

For iOS devices, the permissions can be given by adding the following to the Info.plist file which is located at <project root>/ios/Runner/Info.plist as shown:

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>


Step 3 : Adding VideoPlayerController

The VideoPlayerController facilitates the video playback and control of the video. It establishes the connection to the video and prepare the controller for playback. The Controller that we will be creating here will be a StatefulWidget with a state class. We will initialize the controller using the initState method as shown below:


Step 4 : Displaying & Playing the video:

The VideoPlayer widget from the video_player plugin is used in flutter to display a video. To control the Aspect ratio of the video, we will wrap it inside a AspectRatio Widget. We will also be adding a FloatingActionButton to control the play and pause of the video as shown below:


Complete Source Code:


To know more about FloatingActionButton refer this article: Flutter – FloatingActionButton

Output :

Comment
Article Tags:

Explore