Hey Jerome,
Im facing an issue for both android and ios where Im not able to move to the next item in my pageview as long as the AudioManager.instance.next function is part of the function tree. None of the AudioManager functions are skipable. They basically block the Pageview controlls.
As you will see in my demo, if I slide to the next element, its getting stuck completely, it doesnt let me override the previous action. Also If I press the close button with AudioManager.instance.stop function. It will either get stuck or it wont stop and song will be played on different screen.
This is another or combining issue. If you call the AudioManager.instance.stop(); function and move to a different screen, the song doesnt stop, it continues playing on a different screen. On iOS you can clearly see that this behaviour happens if you slide threw the items and close the screen. It doesnt get recognized anymore. If I put a print in a dispose tree, it will get printed but it doesnt dispose the Audio if you move to a different screen.
In the following im providing you a fully working demo with audio sources from my firebase project. You can test and reproduce the error there. Im also providing 2 videos, one with android from stackoverflow user, where it just looks fine and one from me with iOS, where you can clearly see that it starts playing audio even if we call AudioManager.instance.stop();
Videos:
Android: https://streamable.com/sepgb1
iOS: https://streamable.com/e/ycxwob
import 'package:audio_manager/audio_manager.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int currentIndex = 0;
@override
Widget build(BuildContext context) {
// Page selector for tab list
void _selectPage(int index) {
print('page index: $index');
setState(() {
currentIndex = index;
});
}
// Routes list for tab navigation Android
final List<Widget> _pages = [
ScreenA(),
ScreenB(func: _selectPage),
];
return Scaffold(
appBar: AppBar(),
body: _pages[currentIndex],
bottomNavigationBar: SafeArea(
child: BottomNavigationBar(
onTap: _selectPage,
iconSize: 22,
currentIndex: currentIndex,
type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
backgroundColor: Theme.of(context).primaryColor,
icon: Icon(Icons.description),
label: 'ScreenA',
),
BottomNavigationBarItem(
backgroundColor: Theme.of(context).primaryColor,
icon: Icon(Icons.ac_unit_outlined),
label: 'ScreenB'),
],
),
),
);
}
}
class ScreenA extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Text('HOME'),
);
}
}
class ScreenB extends StatefulWidget {
Function func;
ScreenB({Key key, @required this.func}) : super(key: key);
@override
_ScreenBState createState() => _ScreenBState();
}
var audioFiles = [
"https://docs.google.com/uc?export=open&id=1SaJWqfQuHnFtL7uqrzfYG31hzOnqDM3r",
"https://docs.google.com/uc?export=open&id=1FZkFMjQyWguAl0RMAsYDEZ07c_Qf7gjz",
"https://docs.google.com/uc?export=open&id=1GqrwQ3eRuiil0p-Na_R1tMAvggp9YrbH",
];
var audioIndex = 0;
class _ScreenBState extends State<ScreenB> {
var _controller = PageController();
PlayMode playMode = AudioManager.instance.playMode;
var globalIndex =0;
@override
void initState() {
// TODO: implement initState
List<AudioInfo> _list = [];
for (var i = 0; i < audioFiles.length; i++) {
_list.add(AudioInfo(audioFiles[i], coverUrl: '', desc: '', title: ''));
}
print(_list);
AudioManager.instance.audioList = _list;
AudioManager.instance.intercepter = true;
AudioManager.instance.play(auto: true);
super.initState();
}
@override
void dispose() {
// TODO: implement dispose
AudioManager.instance.release();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
actions: [
IconButton(
icon: Icon(Icons.close),
onPressed: () {
AudioManager.instance.stop();
widget.func(0);
},
),
],
),
body: PageView.custom(
dragStartBehavior: DragStartBehavior.start,
controller: _controller,
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.horizontal,
childrenDelegate: SliverChildBuilderDelegate((ctx, pageIndex) =>
GestureDetector(
onPanUpdate: (details) {
if (details.delta.dx < 0) {
_controller.nextPage(
duration: Duration(milliseconds: 200),
curve: Curves.easeInOut);
setState(() {
//audioIndex = pageIndex;
AudioManager.instance.next();
});
}
},
child: Center(
child: Container(
width: 200,
height: 200,
color: Colors.red,
child: Text(audioFiles[audioIndex])))))),
);
}
}