jhomlala / betterplayer

Better video player for Flutter, with multiple configuration options. Solving typical use cases!
Apache License 2.0
927 stars 1.02k forks source link

better_player will not play immediately after seek to begin and play again #623

Closed giasuddin2548 closed 3 years ago

giasuddin2548 commented 3 years ago

History check Please confirm that you've checked issues history and you didn't find anything which may solve your issue.

Describe the bug I want to skip the video with default position, before applying mvvm pettern in my project it's works perfectly, after applying mvvm pettern when i'm trying to skip video will not play immediately after seek to begin and play again.

My Model class ` class VideoService {

var dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://firebasestorage.googleapis.com/v0/b/file-upload-c801a.appspot.com/o/Filhaal2%20Mohabbat%20-%20Akshay%20Kumar%20Ft%20Nupur%20Sanon%20-%20Ammy%20Virk%20-%20BPraak%20-%20Jaani%20-%20Arvindr%20Khaira.mkv?alt=media&token=947fccf2-cfa7-4058-856c-d06172014a91", // "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4", // resolutions: { // "256P": // "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4", // "720P": // "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_640_3MG.mp4", // "1080P": // "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1280_10MG.mp4", // "4K": // "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1920_18MG.mp4" // }, notificationConfiguration: BetterPlayerNotificationConfiguration( showNotification: true, title: "Elephant dream", author: "Some author", imageUrl: "https://upload.wikimedia.org/wikipedia/commons/thumb/3/37/African_Bush_Elephant.jpg/1200px-African_Bush_Elephant.jpg", activityName: "MainActivity", ), );

late BetterPlayerConfiguration _configuration; late BetterPlayerController _controller; late BetterPlayerDataSource _dataSource;

Future initializeVideoService() async{

_configuration = BetterPlayerConfiguration(
    aspectRatio: 16 / 9,
    allowedScreenSleep: false,
    autoDispose: true,
    autoPlay: true,
    looping: true,
    autoDetectFullscreenDeviceOrientation: true,
    controlsConfiguration: BetterPlayerControlsConfiguration(
      enableQualities: true,
      enableSubtitles: true,
      progressBarPlayedColor: Colors.red,
      progressBarHandleColor: Colors.red,
      progressBarBackgroundColor: Colors.grey,
      progressBarBufferedColor: Colors.blueGrey,
      controlBarColor: Colors.black26,
      enableMute: true,

    ));

_dataSource = BetterPlayerDataSource(
  BetterPlayerDataSourceType.network,
  'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
  notificationConfiguration: BetterPlayerNotificationConfiguration(
    showNotification: true,
    title: "Elephant dream",
    author: "Some author",
    imageUrl:
        "https://upload.wikimedia.org/wikipedia/commons/thumb/3/37/African_Bush_Elephant.jpg/1200px-African_Bush_Elephant.jpg",
    activityName: "MainActivity",
  ),
);

_controller = BetterPlayerController(
  _configuration,
  betterPlayerPlaylistConfiguration: BetterPlayerPlaylistConfiguration(
      nextVideoDelay: Duration(seconds: 3)),
  betterPlayerDataSource: dataSource,
);

}

BetterPlayerController get controller { return this._controller; } }`

My Repository `class VideoPlayerRepository{

VideoService _videoService=VideoService();

void videoPlayerInitialize()=>_videoService.initializeVideoService();

BetterPlayerController controller () =>_videoService.controller;

} **ViewModel** class VideoPlayerViewModel with ChangeNotifier {

VideoPlayerRepository _videoPlayerRepository = VideoPlayerRepository(); late BetterPlayerController controller=_videoPlayerRepository.controller();

void videoPlayerInitialize() { _videoPlayerRepository.videoPlayerInitialize(); notifyListeners(); }

}`

My Widget

`class HomePageScreen extends StatefulWidget { @override _HomePageScreenState createState() => _HomePageScreenState(); }

class _HomePageScreenState extends State {

@override void initState() { super.initState(); Provider.of(context,listen: false).videoPlayerInitialize(); // Provider.of(context,listen: false).setController(); // _controller=Provider.of(context).controller; }

@override void dispose() {

super.dispose();

}

@override Widget build(BuildContext context) {

return Scaffold(

  body: Column(
    children: [
      Consumer<VideoPlayerViewModel>(
        builder: (context, value, child) {

          return AspectRatio(
            aspectRatio: value.controller.getAspectRatio()!.toDouble(),
            child: BetterPlayerMultipleGestureDetector(
              onTap: () {

              },

              child: BetterPlayer(
                controller: value.controller,
              ),
            ),
          );

        },
      ),

    ],
  ),

);

}

}`

Flutter doctor I/BufferQueueProducer(11652): [SurfaceTexture-0-11652-32](this:0x71070fb800,id:32,api:3,p:11652,c:11652) queueBuffer: slot 4 is dropped, handle=0x71075726c0 D/AudioTrack(11652): pause(): 0x710755f800, mState = 0 V/jhw (11652): call Intent.migrateExtraStreamToClipData(1) V/jhw (11652): call Intent.migrateExtraStreamToClipData(1) W/System (11652): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar I/System.out(11652): e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp D/AudioTrack(11652): stop(): 0x710755f800, mState = 4 D/AudioTrack(11652): ~AudioTrack(): 0x710755f800 D/AudioTrack(11652): stop(): 0x710755f800, mState = 4 W/System (11652): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar I/System.out(11652): e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp I/System.out(11652): [OkHttp] sendRequest>> I/System.out(11652): [OkHttp] sendRequest<< D/AudioTrack(11652): set: Create AudioTrackThread, tid = 22077 D/AudioTrack(11652): Client defaulted notificationFrames to 6000 for frameCount 12000 D/AudioTrack(11652): createTrack_l: 0x710755f800, mCblk = 0x70fb280000, mLatency = 335, mAfLatency = 85, frameCount = 12000, mSampleRate = 48000, mFlags = 0x8, mReqFrameCount = 12000, mNotificationFramesAct = 6000 I/BufferQueueProducer(11652): [SurfaceTexture-0-11652-32](this:0x71070fb800,id:32,api:3,p:11652,c:11652) queueBuffer: fps=2.34 dur=3846.78 max=3202.76 min=18.10 I/AudioTrack-JNI(11652): audioTrack continuously zero data counter >= 10, send pause/stop state to pg, counter: 0 I/AudioTrack(11652): audioTrack continuously zero data counter >= 20, send pause/stop state to pg, counter: 20 D/AudioTrack(11652): start(): 0x710755f800, mState = 1 V/jhw (11652): call Intent.migrateExtraStreamToClipData(1) I/BufferQueueProducer(11652): [SurfaceTexture-0-11652-32](this:0x71070fb800,id:32,api:3,p:11652,c:11652) queueBuffer: slot 13 is dropped, handle=0x7107573380

Better Player version

Smartphone (please complete the following information):

giasuddin2548 commented 3 years ago

it's working fine after removing cashe.