flutter vlc player plugin
a vlc-powered alternative to flutter’s video_player that supports ios and android.
installation
ios
if you’re unable to view media loaded from an external source, you should also add the following:
<key>nsapptransportsecurity</key>
<dict>
<key>nsallowsarbitraryloads</key>
<true/>
</dict>
for more information, or for more granular control over your app transport security (ats) restrictions, you should
read apple’s documentation.
make sure that following line in <project root>/ios/podfile
uncommented:
platform :ios, '9.0'
note: while the flutter
video_player
is not functional on ios simulators, this package (flutter_vlc_player
) is
fully functional on ios simulators.
to enable vlc cast functionality for external displays (chromecast), you should also add the following:
<key>nslocalnetworkusagedescription</key>
<string>used to search for chromecast devices</string>
<key>nsbonjourservices</key>
<array>
<string>_googlecast._tcp</string>
</array>
android
to load media/subitle from an internet source, your app will need the internet
permission.
this is done by ensuring your <project root>/android/app/src/main/androidmanifest.xml
file contains a uses-permission
declaration for android.permission.internet
:
<uses-permission android:name="android.permission.internet" />
as flutter includes this permission by default, the permission is likely already declared in the file.
note that if you got “cleartext http traffic to * is not permitted”
you need to add the android:usescleartexttraffic="true"
flag in the androidmanifest.xml file, or define a new “network security configuration” file. for more information, check https://developer.android.com/training/articles/security-config
in order to load media/subtitle from internal device storage, you should put the storage permissions as follows:
<uses-permission android:name="android.permission.write_external_storage"/>
<uses-permission android:name="android.permission.read_external_storage"/>
in some cases you also need to add the android:requestlegacyexternalstorage="true"
flag to the application tag in androidmanifest.xml file to avoid acess denied errors. android 10 apps can’t acess storage without that flag. reference
after that you can access the media/subtitle file by
"/storage/emulated/0/{filepath}"
"/sdcard/{filepath}"
android build configuration
- in
android/app/build.gradle
:
android {
packagingoptions {
// fixes duplicate libraries build issue,
// when your project uses more than one plugin that depend on c++ libs.
pickfirst 'lib/**/libc++_shared.so'
}
buildtypes {
release {
minifyenabled true
useproguard true
proguardfiles getdefaultproguardfile(
'proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
}
- create
android/app/proguard-rules.pro
, add the following lines:
-keep class org.videolan.libvlc.** { *; }
quick start
to start using the plugin, copy this code or follow the example project in ‘flutter_vlc_player/example’
import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
void main() {
runapp(myapp());
}
class myapp extends statelesswidget {
// this widget is the root of your application.
@override
widget build(buildcontext context) {
return materialapp(
title: 'flutter demo',
theme: themedata(
visualdensity: visualdensity.adaptiveplatformdensity,
),
home: myhomepage(),
);
}
}
class myhomepage extends statefulwidget {
myhomepage({key key}) : super(key: key);
@override
_myhomepagestate createstate() => _myhomepagestate();
}
class _myhomepagestate extends state<myhomepage> {
vlcplayercontroller _videoplayercontroller;
@override
void initstate() {
super.initstate();
_videoplayercontroller = vlcplayercontroller.network(
'https://media.w3.org/2010/05/sintel/trailer.mp4',
hwacc: hwacc.full,
autoplay: false,
options: vlcplayeroptions(),
);
}
@override
void dispose() async {
super.dispose();
await _videoplayercontroller.stoprendererscanning();
await _videoplayercontroller.dispose();
}
@override
widget build(buildcontext context) {
return scaffold(
appbar: appbar(),
body: center(
child: vlcplayer(
controller: _videoplayercontroller,
aspectratio: 16 / 9,
placeholder: center(child: circularprogressindicator()),
),
),
);
}
}
upgrade instructions
version 5.0 upgrade for existing apps
to upgrade to version 5.0 first you need to migrate the existing project to swift.
- clean the repo:
git clean -xdf
- delete existing ios folder from root of flutter project. if you have some custom changes made to the ios app – rename it or copy somewhere outside the project.
- re-create the ios app: this command will create only ios directory with swift support. see https://stackoverflow.com/questions/52244346/how-to-enable-swift-support-for-existing-project-in-flutter
flutter create -i swift .
- make sure to update the project according to warnings shown by the flutter tools. (update info.plist, podfile).
if you have some changes made to the ios app, recreate the app using above method and copy in the changed files.
be sure to follow instructions above after
Comments are closed.