Closed Waxxymwansa closed 4 years ago
Closing, as it is not a valid bug report.
I think since you're not reporting a bug, but just asking for help, it would be better for you to ask on appropriate forums such as StackOverflow or Gitter.
Thanks for understanding.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.
I wanted to view an example of how to add a custom queue to the Audio service. I am returning a json that has a list of music. But i am unable to Add this to the audio service background and run it. Please help. This is an example of my player class. The songModel Has all the song data
`import 'package:audio_service/audio_service.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:rxdart/rxdart.dart'; import 'Songs.dart'; import 'backgroundTask.dart';
class Player extends StatefulWidget { SongModel songModel; Player({@required this.songModel}); @override _Player createState() => _Player(); }
class _Player extends State {
static SongModel data;
List songs;
@override
Future initState() {
super.initState();
data = widget.songModel;
songs = data.songs;
// setSongs(data.songs);
}
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: StreamBuilder(
stream: _screenStateStream,
builder: (context, snapshot) {
final screenState = snapshot.data;
final queue = screenState?.queue;
final mediaItem = screenState?.mediaItem;
final state = screenState?.playbackState;
final basicState = state?.basicState ?? BasicPlaybackState.none;
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(data.currentSong.title),
Text(data.songs.length.toString()),
Column(mainAxisAlignment: MainAxisAlignment.center, children: [
if (queue != null && queue.isNotEmpty)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
icon: Icon(Icons.skip_previous),
iconSize: 64.0,
onPressed: mediaItem == queue.first
? null
: AudioService.skipToPrevious,
),
IconButton(
icon: Icon(Icons.skip_next),
iconSize: 64.0,
onPressed: mediaItem == queue.last
? null
: AudioService.skipToNext,
),
if (mediaItem?.title != null) Text(mediaItem.title),
],
),
]),
if (mediaItem?.title != null) Text(mediaItem.title),
if (basicState == BasicPlaybackState.playing)
RaisedButton(child: Text("Pause"), onPressed: pause)
else if (basicState == BasicPlaybackState.buffering ||
basicState == BasicPlaybackState.skippingToNext ||
basicState == BasicPlaybackState.skippingToPrevious)
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: 64.0,
height: 64.0,
child: CircularProgressIndicator(),
),
)
else if (state != BasicPlaybackState.stopped)
RaisedButton(child: Text("Stop"), onPressed: stop),
RaisedButton(child: Text("Play"), onPressed: play),
RaisedButton(child: Text("StartService"),onPressed:()=> start(data.songs))
],
);
},
)),
);
}
}
_backgroundTaskEntrypoint(){
AudioServiceBackground.run(() => AudioPlayerTask()); }
start(data) { AudioService.start( backgroundTaskEntrypoint:_backgroundTaskEntrypoint, androidNotificationChannelName: 'com.zimosound_app.us', notificationColor: 0xFF2196f3, androidNotificationIcon: 'mipmap/ic_launcher', enableQueue: true, ); AudioServiceBackground.setQueue(data); print("These are my songs in my class-----------------------------!!77!"); print(AudioService.queue); }
stop() => AudioService.stop();
play() async { if (await AudioService.running) { AudioService.play(); } }
pause() => AudioService.pause();
Stream get _screenStateStream =>
Rx.combineLatest3<List, MediaItem, PlaybackState, ScreenState>(
AudioService.queueStream,
AudioService.currentMediaItemStream,
AudioService.playbackStateStream,
(queue, mediaItem, playbackState) =>
ScreenState(queue, mediaItem, playbackState));
class ScreenState { final List queue;
final MediaItem mediaItem;
final PlaybackState playbackState;
ScreenState(this.queue, this.mediaItem, this.playbackState); } `