pod_player icon indicating copy to clipboard operation
pod_player copied to clipboard

Problem after build

Open SarthakGupta2912 opened this issue 1 year ago • 6 comments

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 avatar Jun 02 '24 11:06 SarthakGupta2912

`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<MicroLearningPage> { List<CarouselController> buttonCarouselControllers = []; late List<List<PodPlayerController>> controller = [];

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

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

final List<String> 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<String>> 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<String> 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), ], ), ], ), ], ), ], ); }, ), ), ], ), ); } } `

SarthakGupta2912 avatar Jun 02 '24 12:06 SarthakGupta2912

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

newtaDev avatar Jun 02 '24 12:06 newtaDev

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.

SarthakGupta2912 avatar Jun 02 '24 12:06 SarthakGupta2912

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 avatar Jun 07 '24 14:06 ltlalka

@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.

ltlalka avatar Jun 07 '24 15:06 ltlalka

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!

TinhHuynh avatar Jul 03 '24 02:07 TinhHuynh