Home > front end >  How to download videos to app, and make it accessible only through the app (Similarly to Youtube/Net
How to download videos to app, and make it accessible only through the app (Similarly to Youtube/Net

Time:01-18

I'm currently searching for a feature that downloads the videos to the app. The downloaded video will only be accessible through the app just like Youtube and Netflix and will be hidden/encrypted from the gallery. Would greatly appreciate it if someone could point me in the right direction in building this feature.

CodePudding user response:

Using the Path provider package.

You can use getApplicationSupportDirectory() for iOS and getApplicationDocumentsDirectory() for Android.

Like so:

  var dir = await (Platform.isIOS
      ? getApplicationSupportDirectory()
      : getApplicationDocumentsDirectory());
  File videoFile = File("${dir.path}/video.mp4");

CodePudding user response:

We have used vdocipher_flutter for this type of feature. This library will helpful to play the downloaded videos which is available for app only.

To download the video you need to integrate Android Library of VdoCipher, You can use it via Method Channel in Flutter

Here is the example code:

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:vdocipher_flutter/vdocipher_flutter.dart';
import 'package:vdocipher_flutter_example/vdoplayback_view.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'VdoCipher Sample Application',
      home: MyHome(),
      theme: ThemeData(
          primaryColor: Colors.white,
          textTheme: TextTheme(bodyText1: TextStyle(fontSize: 12.0))),
    );
  }
}

class MyHome extends StatefulWidget {
  @override
  _MyHomeState createState() => _MyHomeState();
}

class _MyHomeState extends State<MyHome> {
  String? _nativeAndroidLibraryVersion = 'Unknown';

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> getNativeAndroidLibraryVersion() async {
    String? version;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      version = await VdocipherMethodChannel.nativeAndroidLibraryVersion;
    } on PlatformException {
      version = 'Failed to get native android library version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _nativeAndroidLibraryVersion = version;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('VdoCipher Sample Application'),
        ),
          body: Center(child: Column(
            children: <Widget>[
              Expanded(child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    ElevatedButton(
                      onPressed: _goToVideoPlayback,
                      child: const Text('Online Playback',
                          style: TextStyle(fontSize: 20)),
                    ),
                    ElevatedButton(
                      onPressed: null,
                      child: const Text('Todo: video selection',
                          style: TextStyle(fontSize: 20)),
                    )
                  ])),
              Padding(padding: EdgeInsets.all(16.0),
                  child: Text('Native android library version: $_nativeAndroidLibraryVersion',
                      style: TextStyle(color: Colors.grey, fontSize: 16.0)))
            ],
          )))
    );
  }

  void _goToVideoPlayback() {
    Navigator.of(context).push(
      MaterialPageRoute<void>(
        builder: (BuildContext context) {
          return VdoPlaybackView();
        },
      ),
    );
  }
}

Note: It is paid and available for Android only.

  •  Tags:  
  • Related