Video not play after navigation click

Viewed 149

I run the video with fijkplayer, when click on the video link in my drawer it just changes the video according to the url, but video not run and change. Please someone help me to solved my problem, i'am new in flutter, I've spent days to solve this, but the problem can't be solved

   import 'package:MyIPTV/src/bloc/navigation_bloc.dart';
import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final FijkPlayer player = FijkPlayer();
  @override
  void startPlay(newUrl) async {
    await player.setOption(FijkOption.hostCategory, "request-screen-on", 1);
    await player.setOption(FijkOption.hostCategory, "request-audio-focus", 1);
    await player.setDataSource(newUrl, autoPlay: true).catchError((e) {
      print("setDataSource error: $e");
    });
  }

  void initState() {
    super.initState();
    player.setOption(FijkOption.hostCategory, "enable-snapshot", 1);
    player.setOption(FijkOption.playerCategory, "mediacodec-all-videos", 1);
  }

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      drawer: Drawer(
        width: MediaQuery.of(context).size.width / 2,
        child: Column(
          children: <Widget>[
            UserAccountsDrawerHeader(
                accountName: Text("Admin"),
                currentAccountPicture: CircleAvatar(child: Icon(Icons.person)),
                accountEmail: Text("12345@gmail.com")),
            ListTile(
              title: Text("Video 1"),
              onTap: () {
                // Navigator.of(context).pop();
                bloc.updateNavigation(
                    "https://v2.siar.us/aditv/livestream/chunks.m3u8");
              },
            ),
            ListTile(
              title: Text("Page One"),
              onTap: () {
                // Navigator.of(context).pop();
                bloc.updateNavigation(
                    "https://v2.siar.us/aditv/livestream/chunks.m3u8");
              },
            ),
            ListTile(
              title: Text("Page Two"),
              onTap: () {
                // Navigator.of(context).pop();
                bloc.updateNavigation(
                    "https://v2.siar.us/aditv/livestream/chunks.m3u8");
              },
            ),
          ],
        ),
      ),
      body: StreamBuilder(
        stream: bloc.getNavigation,
        initialData: bloc.navigationProvider.currentNavigation,
        builder: (context, snapshot) {
          if (bloc.navigationProvider.currentNavigation != '') {
            print(bloc.navigationProvider.currentNavigation.toString());
            startPlay(bloc.navigationProvider.currentNavigation.toString());

            return FijkView(
              player: player,
              panelBuilder: fijkPanel2Builder(snapShot: true),
              fsFit: FijkFit.fill,
            );
          }

          return CircularProgressIndicator();
        }, // access the data in our Stream here
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
    player.release();
  }
}

I run the video with fijkplayer, when click on the video link in my drawer it just changes the video according to the url, but video not run and change. Please someone help me to solved my problem, i'am new in flutter, I've spent days to solve this, but the problem can't be solved

1 Answers

You need to call _keyDrawer.currentState!.openEndDrawer() whenever you tap on ListTile like below -

    ListTile(
         title: Text('Video 1'),
         onTap: () {
           _keyDrawer.currentState!.openEndDrawer();
           newUrl('https://v2.siar.us/aditv/livestream/chunks.m3u8');
      },
   )
Related