You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently trying to use stereo to play background music in my app and I keep receiving issues whenever I call the load(String) from the Stereo.dart class.
Whenever I looked further into the issue I figured out that the issue comes directly from the AudioTrack.java class whenever this line is called
mmr.setDataSource(path);
To replicate the issue, just add this code into the example project.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:stereo/stereo.dart';
void main() {
runApp(new MaterialApp(home: new ExampleApp()));
}
class ExampleApp extends StatefulWidget {
@override
_ExampleAppState createState() => new _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
Stereo _stereo;
@override
initState() {
super.initState();
_stereo = new Stereo();
_playMusic();
}
_playMusic() async {
await _copyFiles();
await _loadMusic();
}
_loadMusic() async {
String dir = '';
String mp3 = "pi.mp3";
await getApplicationDocumentsDirectory().then(
(Directory directory) => dir = 'file://' + directory.path + '/');
try {
await _stereo.load('$dir$mp3');
// _stereo.play();
} on StereoFileNotPlayableException {
var alert = new AlertDialog(
title: new Text('File not playable'),
content: new Text('The file you specified is not playable.'));
showDialog(context: context, child: alert);
}
}
_copyFiles() async {
final Directory dir = await getApplicationDocumentsDirectory();
final File song = new File('${dir.path}/pi.mp3');
if (!(await song.exists())) {
final data = await rootBundle.load('assets/songs/pi.mp3');
final bytes = data.buffer.asUint8List();
await song.writeAsBytes(bytes, flush: true);
}
}
@override
Widget build(BuildContext context) {
return Material(
child: Scaffold(
body: Container(),
),
);
}
}
Currently trying to use stereo to play background music in my app and I keep receiving issues whenever I call the
load(String)
from theStereo.dart
class.Whenever I looked further into the issue I figured out that the issue comes directly from the
AudioTrack.java
class whenever this line is calledmmr.setDataSource(path);
To replicate the issue, just add this code into the example project.
Flutter --version
The text was updated successfully, but these errors were encountered: