video_launcher 0.2.2

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

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

To launch a video :

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

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';
    }
  }

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

Getting Started #

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

Changelog #

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:http/http.dart';
import 'package:video_launcher/video_launcher.dart';
import 'package:path_provider/path_provider.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;

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

  @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),
                ),
                /*new Row(mainAxisSize: MainAxisSize.min, children: [*/
                  _buildButton('Play online', _launch),
                  _buildButton('Download', localVideoPath != null ? null : _loadVideo),
                  _buildButton('Play local', localVideoPath != null ? _launchLocal : null),
                /*]),*/
              ],
            ),
            new FutureBuilder<Null>(future: _launched, builder: _launchStatus),
          ],
        ),
      ),
    );
  }


  void _launch() {
    setState(() {
      _launched = _launchVideo(videoUrl);
    });
  }
  void _launchLocal() {
    setState(() {
      _launched = _launchVideo(localVideoPath, 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;
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  video_launcher: ^0.2.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub 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
Popularity:
Describes how popular the package is relative to other packages. [more]
49
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
25
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0