bcc-code / bccm-player

[BCC Media] Flutter package for video-heavy apps
https://bcc-code.github.io/bccm-player/
Other
17 stars 11 forks source link

ADD support to play video files present in internal storage in android #30

Closed PURUSHOTHAM-REDDY-N closed 1 year ago

PURUSHOTHAM-REDDY-N commented 1 year ago

can you add support to play video files present in internal file system of android.

sudhanshugairola commented 1 year ago

controller = BccmPlayerController( MediaItem( url: /data/user/0/download/video.mp4', mimeType: 'application/x-mpegURL', metadata: MediaMetadata(title: 'TEST'), ), );

use path provider

andreasgangso commented 1 year ago

@sudhanshugairola are you saying this works?

sudhanshugairola commented 1 year ago

Yes playing but control like play pause and seekbar not working

sudhanshugairola commented 1 year ago

But video is playing yet

PURUSHOTHAM-REDDY-N commented 1 year ago

is there any way that we can have all the controls ? @andreasgangso @sudhanshugairola

sudhanshugairola commented 1 year ago

wait for developer final review they will fix controls issue and gettracks for offline file playing.

andreasgangso commented 1 year ago

Hi @sudhanshugairola @PURUSHOTHAM-REDDY-N I have just tested playing files from internal storage on android, and it works without issues (play/pause/seek, etc) I tested both HLS (m3u8) and mp4.

Example for Mp4

  MediaItem(
    url: 'file:////storage/emulated/0/Download/demo.mp4',
    mimeType: 'video/mp4',
    metadata: MediaMetadata(title: 'Local file (mp4)'),
  ),

Example for HLS:

  MediaItem(
    url: 'file:////storage/emulated/0/Download/hls/main.m3u8',
    mimeType: 'application/x-mpegURL',
    metadata: MediaMetadata(title: 'Local file (HLS)'),
  ),

For the URL, you may need to start with "file:///", but it also worked with just "/storage/emulated/0/...".

If this does not work, check these things.

If it still does not work, please post your entire log inside a collapsable section, to help debug this.

In the future we'll make it easier to use files and assets in a cross-platform way.

sudhanshugairola commented 1 year ago

you are right its working now, but issue with subtitle field on m3u8 if there is only one subtitle then it now come in tracksData.textTracks

sudhanshugairola commented 1 year ago

in online playing it working well, but that issue i got with internal storage m3u8

andreasgangso commented 1 year ago

you are right its working now, but issue with subtitle field on m3u8 if there is only one subtitle then it now come in tracksData.textTracks

If there's a subtitle track, it makes sense that it shows up in textTracks. I don't understand how this is a problem.

Please keep your messages in 1, github isn't a chat :) It's better to edit your original. And don't reply with just "ok", use the emoji button on my message instead :)

sudhanshugairola commented 1 year ago

if (tracksData != null && tracksData.textTracks.length >= 1) by this i got subtitle, now working well.

PURUSHOTHAM-REDDY-N commented 1 year ago

@andreasgangso @sudhanshugairola im using local files to play video, it is playing but controls for play , pause and seek bar not working , when i tried to press skip, video is playing from start

this is my implementatioin

import 'dart:async'; import 'package:flutter/material.dart'; import 'dart:io'; import 'package:permission_handler/permission_handler.dart'; import 'package:bccm_player/bccm_player.dart';

class VideoPlayerScreen extends StatefulWidget { final String path;

VideoPlayerScreen({required this.path});

@override _VideoPlayerScreenState createState() => _VideoPlayerScreenState(); }

class _VideoPlayerScreenState extends State { late BccmPlayerController playerController;

@override void initState() { super.initState(); requestPermission(); playerController = BccmPlayerController( MediaItem( url: 'file:////${widget.path}', mimeType: 'video/mp4', metadata: MediaMetadata(title: 'Apple advanced (HLS/HDR)'), ), ); playerController.initialize().then(() => playerController.setMixWithOthers( true)); // if you want to play together with other videos super.initState(); }

@override void dispose() { if (!playerController.isPrimary) { playerController.dispose(); } super.dispose(); }

Future _requestPermission() async { // Requesting the storage permission final status = await Permission.storage.request();

if (status.isGranted) {
} else if (status.isDenied) {}

}

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Video Player'), ), body: BccmPlayerView( config: BccmPlayerViewConfig( allowSystemGestures: false, useSurfaceView: true), playerController, //config: BccmPlayerViewConfig() ), ); } }

sudhanshugairola commented 1 year ago

Did cmd: flutter clean

After that add latest version on your pubspec.yaml bccm_player: ^1.1.1

Use latest version

PURUSHOTHAM-REDDY-N commented 1 year ago

@sudhanshugairola i did flutter clean and im using the latest version bccm_player: ^1.1.1 im still getting this issue

sudhanshugairola commented 1 year ago

That problem is only with old version. I also check it work fine with new version.

PURUSHOTHAM-REDDY-N commented 1 year ago

@sudhanshugairola can you share your configuration code , i will cross check with mine , im using the latest version of this package still im getting this issue

sudhanshugairola commented 1 year ago

Sure wait first I will check your code once

PURUSHOTHAM-REDDY-N commented 1 year ago

@sudhanshugairola check here https://github.com/PURUSHOTHAM-REDDY-N/Flutter-video-player

sudhanshugairola commented 1 year ago

Ah great

On Wed, 23 Aug, 2023, 9:33 am PURUSHOTHAM REDDY, @.***> wrote:

@sudhanshugairola https://github.com/sudhanshugairola check here https://github.com/PURUSHOTHAM-REDDY-N/Flutter-video-player

— Reply to this email directly, view it on GitHub https://github.com/bcc-code/bccm-player/issues/30#issuecomment-1689247051, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKCFO6BKCTMXPLGPJ2YQ6DTXWV6I3ANCNFSM6AAAAAA3WS5URM . You are receiving this because you were mentioned.Message ID: @.***>

sudhanshugairola commented 1 year ago
import 'dart:io';
import 'package:bccm_player/bccm_player.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:bccm_player/src/pigeon/playback_platform_pigeon.g.dart';
import 'package:bccm_player/src/widgets/controls/default/settings_option_list.dart';
import 'package:bccm_player/theme/bccm_player_theme.dart';

import 'package:collection/collection.dart';
import 'package:universal_io/io.dart';

class SinglePlayer extends StatefulWidget {
  const SinglePlayer({key});

  @override
  State<SinglePlayer> createState() => _SinglePlayerState();
}

class _SinglePlayerState extends State<SinglePlayer> {
  late BccmPlayerController controller;

  @override
  void initState() {
    // You can also use the global "primary" controller.
    // The primary player has superpowers like notification player, background playback, casting, etc:
    // final controller = BccmPlayerInterface.instance.primaryController;
    controller = BccmPlayerController(
      MediaItem(
        url: '/data/user/0/com.test.bcc/app_flutter/newtest.m3u8',
        mimeType: 'application/x-mpegURL',
        metadata: MediaMetadata(title: 'TEST'),
      ),
    );

    controller.initialize().then((_) => controller.setMixWithOthers(false)); // if you want to play together with other videos
    super.initState();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final tracksFuture = controller.getTracks();
    return Scaffold(
      appBar: AppBar(
        title: Text("new")
      ),
      backgroundColor: Colors.black,
      body:ListView(
      children: [
        Column(
          children: [
            BccmPlayerView(
              controller,
              //config: BccmPlayerViewConfig()
            ),
            ElevatedButton(
              onPressed: () {
                final currentMs = controller.value.playbackPositionMs;
                if (currentMs != null) {
                  controller.seekTo(Duration(milliseconds: currentMs + 20000));
                }
              },
              child: const Text('Skip 20 seconds'),
            ),
            ElevatedButton(
              onPressed: () {
                print(controller.value.playbackState);
                final currentMs = controller.value.playbackPositionMs;
                if (currentMs != null) {
                  if(controller.value.playbackState == PlaybackState.playing){
                    controller.pause();
                  }
                  else{
                    controller.play();
                  }
                }
              },
              child: const Text('Play'),
            ),
            ElevatedButton(
              onPressed: () {
                controller.enterNativeFullscreen();
              },
              child: const Text('Full screen'),
            ),
            ElevatedButton(
              onPressed: () {
                // print("asssss ${controller.value.}");
                // controller.dispose();
              },
              child: const Text('Exit Player'),
            ),
          ],
        ),
      ],
      ),
    );
  }
}
PURUSHOTHAM-REDDY-N commented 1 year ago

@sudhanshugairola controls are working only when i click on full screen button controller.enterNativeFullscreen();

sudhanshugairola commented 1 year ago

You mean native controls?

PURUSHOTHAM-REDDY-N commented 1 year ago

in ui we have a button to go full screen

controller.enterNativeFullscreen();

PURUSHOTHAM-REDDY-N commented 1 year ago

@sudhanshugairola there any method to initialize player default with NativeFullscreen

sudhanshugairola commented 1 year ago

ok you want full screen with native controls, as you reach to videoplayer page?

PURUSHOTHAM-REDDY-N commented 1 year ago

yes

sudhanshugairola commented 1 year ago
import 'dart:io';
import 'package:auto_orientation/auto_orientation.dart';
import 'package:bccm_player/bccm_player.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:bccm_player/src/pigeon/playback_platform_pigeon.g.dart';
import 'package:bccm_player/src/widgets/controls/default/settings_option_list.dart';
import 'package:bccm_player/theme/bccm_player_theme.dart';

import 'package:collection/collection.dart';
import 'package:universal_io/io.dart';
import 'package:wakelock_plus/wakelock_plus.dart';

class SinglePlayer extends StatefulWidget {
  const SinglePlayer({key});

  @override
  State<SinglePlayer> createState() => _SinglePlayerState();
}

class _SinglePlayerState extends State<SinglePlayer> {
  BccmPlayerController? controller;

  @override
  void initState() {
    WakelockPlus.enable();
    AutoOrientation.landscapeAutoMode(forceSensor: true);
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
    controller = BccmPlayerController(
      MediaItem(
        url: 'you path',
        mimeType: 'application/x-mpegURL',
        metadata: MediaMetadata(title: 'Apple advanced (HLS/HDR)'),
      ),
    );
    controller!.initialize().then((_){
      controller!.setMixWithOthers(true);
    }); // if you want to play together with other videos
    super.initState();
  }

  @override
  void dispose() {
    AutoOrientation.portraitAutoMode();
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
        overlays: SystemUiOverlay.values);
    controller!.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body:Container(
        width: controller?.value.videoSize?.width.roundToDouble() ?? MediaQuery.of(context).size.width,
        height: controller?.value.videoSize?.height.roundToDouble() ?? MediaQuery.of(context).size.height,
        child: VideoPlatformView(
          playerController: controller!, showControls: true,
          allowSystemGestures: true,
          //config: BccmPlayerViewConfig()
        ),
      )
    );
  }
}
sudhanshugairola commented 1 year ago

Custom controls also work on my side with internal storage media files.

import 'dart:io';
import 'package:auto_orientation/auto_orientation.dart';
import 'package:bccm_player/bccm_player.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:bccm_player/src/pigeon/playback_platform_pigeon.g.dart';
import 'package:bccm_player/src/widgets/controls/default/settings_option_list.dart';
import 'package:bccm_player/theme/bccm_player_theme.dart';

import 'package:collection/collection.dart';
import 'package:universal_io/io.dart';
import 'package:wakelock_plus/wakelock_plus.dart';

class SinglePlayer extends StatefulWidget {
  const SinglePlayer({key});

  @override
  State<SinglePlayer> createState() => _SinglePlayerState();
}

class _SinglePlayerState extends State<SinglePlayer> {
  BccmPlayerController? controller;

  @override
  void initState() {
    WakelockPlus.enable();
    AutoOrientation.landscapeAutoMode(forceSensor: true);
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
    controller = BccmPlayerController(
      MediaItem(
        url: 'file://///data/user/0/com.gairola.StreamFlix/app_flutter/download/You/S2 E1 A Fresh Start.m3u8',
        mimeType: 'application/x-mpegURL',
        metadata: MediaMetadata(title: 'Apple advanced (HLS/HDR)'),
      ),
    );
    controller!.initialize().then((_){
      controller!.setMixWithOthers(true);
    }); // if you want to play together with other videos
    super.initState();
  }

  @override
  void dispose() {
    AutoOrientation.portraitAutoMode();
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
        overlays: SystemUiOverlay.values);
    controller!.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body:Container(
        width: controller?.value.videoSize?.width.roundToDouble() ?? MediaQuery.of(context).size.width,
        height: controller?.value.videoSize?.height.roundToDouble() ?? MediaQuery.of(context).size.height,
        child: BccmPlayerView(
          controller!,
          config: BccmPlayerViewConfig(
            useSurfaceView: false,
              allowSystemGestures: true,
          )
        ),
      )
    );
  }
}
sudhanshugairola commented 1 year ago

Check if work then closed this issue as completed.

andreasgangso commented 1 year ago

Hi, I actually accidently removed the possibility to have native controls as part of a major refactor in v1.0.0+. I'll make sure to add it back in the next release

PURUSHOTHAM-REDDY-N commented 1 year ago

ohh ok i wil be waiting for your next release thank you. @andreasgangso

andreasgangso commented 1 year ago

@PURUSHOTHAM-REDDY-N Actually I was wrong. It's still very possible in the current versions, no update needed:

VideoPlatformView(
  playerController: BccmPlayerController.primary,
  showControls: true,
),
PURUSHOTHAM-REDDY-N commented 1 year ago

@andreasgangso controls are working fine now

but when i first time open app and open a video its is showing controls but video is not playing after that when i tried to play another video it is playing perfectly

here is my code

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

class VideoPlayerScreen extends StatefulWidget { final String path;

VideoPlayerScreen({required this.path});

@override _VideoPlayerScreenState createState() => _VideoPlayerScreenState(); }

class _VideoPlayerScreenState extends State { @override void initState() { BccmPlayerController.primary.initialize(); BccmPlayerController.primary.replaceCurrentMediaItem( MediaItem( url: widget.path, mimeType: 'video/*', metadata: MediaMetadata(title: 'TEST'), ), autoplay: true);

super.initState();

}

@override void dispose() { BccmPlayerController.primary.pause(); super.dispose(); }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("new")), backgroundColor: Colors.black, body: ListView( children: [ Center( child: Column( children: [ VideoPlatformView( playerController: BccmPlayerController.primary, showControls: true, ), ElevatedButton( onPressed: () => BccmPlayerController.primary.enterNativeFullscreen(), child: Text("enter")) ], ), ), ], ), ); } }

andreasgangso commented 1 year ago

@PURUSHOTHAM-REDDY-N I'm not sure what could be wrong with your code, but it might be a race condition with initialization. Try making your main async, and call await BccmPlayerInterface.instance.setup();. Let me know if it worked or not:

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await BccmPlayerInterface.instance.setup();
  runApp(const MyApp());
}

Tip: Put your code inside triple-` to format your code like this^ in a comment, see https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting.

PURUSHOTHAM-REDDY-N commented 1 year ago

@andreasgangso it worked ! thank you, but when i tried to play the video controls are not visible if i make the video full screen then the controls are showing it is happening for some files only

and is there any way that we can play the video in full screen by default

this is my repo https://github.com/PURUSHOTHAM-REDDY-N/Flutter-video-player

check this once https://github.com/bcc-code/bccm-player/assets/84611950/0d93b839-6d9d-4d12-a6af-093204d15b77