video_launcher 0.3.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 90

VideoLauncher

Example

cd flutter_video_launcher/example
flutter packages get
flutter run

screenshot

Usage

To use this plugin, add video_launcher as a dependency in your pubspec.yaml file.

After importing 'package:video_launcher/video_launcher.dart' the directories can be queried as follows

Remote video

To launch a video :

Future<Null> _launch(String url) async {
    if (await canLaunchVideo(url)) {
      await launchVideo(url);
    } else {
      throw 'Could not launch $url';
    }
  }

Local video

To play a local video file :

Future<Null> _launch(String url) async {
    if (await canLaunchVideo(url, isLocal:true)) {
      await launchVideo(url, isLocal:true);
    } else {
      throw 'Could not launch $url';
    }
  }

Embedded asset

To play video embedded assets, you can copy them to the app storage folder, and the play them "locally"

void _loadOrLaunchLocalAsset() =>
      localAssetPath != null ? _launchLocalAsset() : copyLocalAsset();

Future copyLocalAsset() async {
  final dir = await getApplicationDocumentsDirectory();
  final file = new File("${dir.path}/video_asset.mp4");
  final videoData = await rootBundle.load("assets/video.mp4");
  final bytes = videoData.buffer.asUint8List();
  file.writeAsBytes(bytes, flush: true);
    setState(() {
    localAssetPath = file.path;
    _launchLocalAsset();
});
}

void _launchLocalAsset() =>
  setState(() => _launched = _launchVideo(localAssetPath, isLocal: true));

Please see the example app of this plugin for a full example.

⚠️ iOS App Transport Security

By default iOS forbids loading from non-https url. To cancel this restriction edit your .plist and add :

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

cf. Configuring App Transport Security Exceptions in iOS

Troubleshooting

If you get a MissingPluginException, try to flutter build apk on Android, or flutter build ios

Getting Started

For help getting started with Flutter, view our online documentation.

Changelog

0.3.0

  • fix the local video playing on android
  • fix the example

0.2.2

  • changed Flutter dependency in pubspec.yaml to an SDK dependency

0.2.1

  • fix the iOS local playing
  • add download/play local in the example

0.2.0

  • android

0.1.0

  • iOS

example/lib/main.dart

import 'dart:async';
import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart';
import 'package:path_provider/path_provider.dart';
import 'package:video_launcher/video_launcher.dart';

void main() {
  runApp(new MyApp());
}

typedef void OnError(Exception exception);

const videoUrl = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4";

/// a video launcher, based on url_launcher
/// can read remote and local files
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Video Launcher',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Video Launcher'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Future<Null> _launched;
  String localVideoPath;
  String localAssetPath;

  _buildButton(String label, VoidCallback onPressed) => new Padding(
      padding: new EdgeInsets.all(12.0),
      child: new RaisedButton(
        onPressed: onPressed,
        child: new Text(label),
      ));

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                new Padding(
                  padding: new EdgeInsets.all(16.0),
                  child: new Text(videoUrl),
                ),
                _buildButton('Play online', _launch),
                _buildButton(
                    'Download', localVideoPath != null ? null : _loadVideo),
                _buildButton(
                    'Play local', localVideoPath != null ? _launchLocal : null),
                _buildButton('Play video asset', _loadOrLaunchLocalAsset),
              ],
            ),
            new FutureBuilder<Null>(future: _launched, builder: _launchStatus),
          ],
        ),
      ),
    );
  }

  void _launch() => setState(() => _launched = _launchVideo(videoUrl));

  void _launchLocal() =>
      setState(() => _launched = _launchVideo(localVideoPath, isLocal: true));

  void _loadOrLaunchLocalAsset() =>
      localAssetPath != null ? _launchLocalAsset() : copyLocalAsset();

  Future copyLocalAsset() async {
    final dir = await getApplicationDocumentsDirectory();
    final file = new File("${dir.path}/video_asset.mp4");
    final videoData = await rootBundle.load("assets/video.mp4");
    final bytes = videoData.buffer.asUint8List();
    await file.writeAsBytes(bytes, flush: true);
    setState(() {
      localAssetPath = file.path;
      _launchLocalAsset();
    });
  }

  void _launchLocalAsset() =>
      _launched = _launchVideo(localAssetPath, isLocal: true);

  Widget _launchStatus(BuildContext context, AsyncSnapshot<Null> snapshot) {
    String info;
    if (snapshot.hasError) {
      return new Text('Error: ${snapshot.error}');
    } else {
      info = localVideoPath != null ? localVideoPath : '';
    }
    return new Padding(
        padding: new EdgeInsets.only(top: 20.0), child: new Text(info));
  }

  Future<Null> _launchVideo(String url, {bool isLocal: false}) async {
    if (await canLaunchVideo(url, isLocal: isLocal)) {
      await launchVideo(url, isLocal: isLocal);
    } else {
      throw 'Could not launch $url';
    }
  }

  Future _loadVideo() async {
    final bytes = await _loadFileBytes(videoUrl,
        onError: (Exception exception) =>
            print('_MyHomePageState._loadVideo => exception ${exception}'));

    final dir = await getApplicationDocumentsDirectory();
    final file = new File('${dir.path}/video.mp4');

    await file.writeAsBytes(bytes);
    if (await file.exists())
      setState(() {
        localVideoPath = file.path;
      });
  }

  Future<Uint8List> _loadFileBytes(String url, {OnError onError}) async {
    Uint8List bytes;
    try {
      bytes = await readBytes(url);
    } on ClientException {
      rethrow;
    }
    return bytes;
  }
}

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  video_launcher: "^0.3.0"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:video_launcher/video_launcher.dart';
        
Version Uploaded Documentation Archive
0.3.0 Sep 6, 2017 Go to the documentation of video_launcher 0.3.0 Download video_launcher 0.3.0 archive
0.2.2 May 25, 2017 Go to the documentation of video_launcher 0.2.2 Download video_launcher 0.2.2 archive
0.2.1 May 16, 2017 Go to the documentation of video_launcher 0.2.1 Download video_launcher 0.2.1 archive
0.2.0+1 May 15, 2017 Go to the documentation of video_launcher 0.2.0+1 Download video_launcher 0.2.0+1 archive
0.2.0 May 15, 2017 Go to the documentation of video_launcher 0.2.0 Download video_launcher 0.2.0 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1
  • Flutter: 0.0.22

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
84 / 100
Health:
Code health derived from static analysis. [more]
95 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
90

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
flutter 0.0.0
Transitive dependencies
async 2.0.3
charcode 1.1.1
collection 1.14.5
http 0.11.3+16
http_parser 3.1.1
meta 1.1.1 1.1.2
path 1.5.1
sky_engine 0.0.99
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.4 1.1.5
vector_math 2.0.5