newtaDev / pod_player

Video player for flutter web & mobile devices, Play video from youtube or vimeo or network in flutter using pod player
https://pub.dev/packages/pod_player
MIT License
103 stars 186 forks source link

Problem after build #208

Open SarthakGupta2912 opened 4 months ago

SarthakGupta2912 commented 4 months ago

When i test my app in the debug mode or using cable then it works fine but after i test the build-release apk then it creates problem. So the problem is that i am trying to play many youtube videos as i have a list of videos. They play very well during debug mode but when i build the app and then test then only the last instance i created is assigned to every video and they play and pause all together.

The below is my code.

SarthakGupta2912 commented 4 months ago

`import 'package:flutter/material.dart'; import 'package:carousel_slider/carousel_slider.dart'; import 'package:pod_player/pod_player.dart';

class MicroLearningPage extends StatefulWidget { const MicroLearningPage({super.key});

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

class _MicroLearningPageState extends State { List buttonCarouselControllers = []; late List<List> controller = [];

final List sectionTitle = [ 'Most Viewed', 'Most Popular', ];

List mostViewedVideoTitles = ['Title1', 'Title2', 'Title3']; List mostPopularVideoTitles = [ 'Title4', 'Title5', 'Title6', 'Title7' ]; final List<List> videoTitles = []; final List videoUrls = [ 'https://www.youtube.com/watch?v=C3aRyxcpy5A', 'https://www.youtube.com/watch?v=UtbwuxoEYt0', 'https://www.youtube.com/watch?v=A3ltMaM6noM', ];

final List videoUrls2 = [ 'https://www.youtube.com/watch?v=gu-z9EbIZ5k', 'https://www.youtube.com/watch?v=ajvXxR1Di54', 'https://www.youtube.com/watch?v=yMNMb1JNqIs', 'https://www.youtube.com/watch?v=UtbwuxoEYt0', ];

late List<List> totalVideoUrlLists = [ videoUrls, videoUrls2, ]; int totalSections = 2, controllerIndex = 0;

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

controller = List.generate(totalSections, (_) => []);
buttonCarouselControllers =
    List.generate(totalSections, (index) => CarouselController());

for (int i = 0; i < totalVideoUrlLists.length; i++) {
  addPodPlayerController(totalVideoUrlLists[i]);
}
videoTitles.add(mostViewedVideoTitles);
videoTitles.add(mostPopularVideoTitles);
debugPrint('MicroLearningPage initialized!');

}

void addPodPlayerController(List videoUrls) { for (int i = 0; i < videoUrls.length; i++) { controller[controllerIndex].add(PodPlayerController( podPlayerConfig: const PodPlayerConfig(autoPlay: false), playVideoFrom: PlayVideoFrom.youtube(videoUrls[i]), )..initialise()); } controllerIndex++; }

void disposeControllers() { for (int i = 0; i < controller.length; i++) { for (int j = 0; j < controller[i].length; j++) { controller[i][j].dispose(); } } }

@override void dispose() { super.dispose(); disposeControllers(); debugPrint('Disposed()'); }

@override Widget build(BuildContext context) { double screenWidth = MediaQuery.of(context).size.width; double screenHeight = MediaQuery.of(context).size.height; return Scaffold( appBar: AppBar( backgroundColor: Colors.green.withOpacity(0.2), title: const Text('Micro Learning'), ), body: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Expanded( child: ListView.builder( itemCount: totalSections, itemBuilder: (BuildContext context, int index) { return Column( children: [ SizedBox(height: screenHeight 0.02), Row( children: [ SizedBox(width: screenWidth 0.04), Text( sectionTitle[index], style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 18, ), ), ], ), SizedBox(height: screenHeight 0.02), Column( children: [ Row( children: [ Column( children: [ IconButton( icon: const Icon( Icons.arrow_back_ios_new_rounded, color: Colors.black, ), onPressed: () { buttonCarouselControllers[index] .previousPage(); }, ), SizedBox(height: screenHeight 0.04), ], ), Expanded( child: CarouselSlider.builder( carouselController: buttonCarouselControllers[index], itemCount: totalVideoUrlLists[index].length, itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) { return Column( children: [ SizedBox( width: screenWidth 0.65, child: PodVideoPlayer( controller: controller[index][itemIndex], ), ), ], ); }, options: CarouselOptions( initialPage: 1, viewportFraction: 0.85, enableInfiniteScroll: false, enlargeCenterPage: true, ), ), ), Column( children: [ IconButton( icon: const Icon( Icons.arrow_forward_ios_rounded, color: Colors.black, ), onPressed: () { buttonCarouselControllers[index].nextPage(); }, ), SizedBox(height: screenHeight 0.04), ], ), ], ), ], ), ], ); }, ), ), ], ), ); } } `

newtaDev commented 4 months ago

Please Refer these example: https://github.com/newtaDev/pod_player/blob/master/example/lib/examples/play_list_of_videos.dart

https://github.com/newtaDev/pod_player/blob/master/example/lib/examples/play_videos_list_dynamically.dart

SarthakGupta2912 commented 4 months ago

Please Refer these example: https://github.com/newtaDev/pod_player/blob/master/example/lib/examples/play_list_of_videos.dart

https://github.com/newtaDev/pod_player/blob/master/example/lib/examples/play_videos_list_dynamically.dart

I did but still not working in the build. However, The problem is only occurring in the build apk.

ltlalka commented 3 months ago

Same on my side. Also examples not working correctly. On debug mode all videos are ok. On release mode, loading same movie to all containers. Checked that on release mode controller initialized with the same url.

Flutter (Channel stable, 3.22.1, on macOS 14.4.1 23E224 darwin-arm64)

ltlalka commented 3 months ago

@newtaDev
One information that can be helpful. After downgrade flutter to 3.19.5, everything works ok. So this is something related with newest Flutter version.

TinhHuynh commented 3 months ago

Hi, the PodPlayerController uses UniqueKey().toString() to generate a tag for the internal PodGetXController. However, in Flutter 3.22, there is an issue that UniqueKey always returns "Instance of UniqueKey" in release mode. No matter how many PodPlayerController are created, they still share the same PodGetXController instance.

I created PR that replaces UniqueKey with UUID for safer tag generation. Hope this will get merged soon!