
我编写了一个Dart Web应用程序,该应用程序从服务器检索.mp3文件并进行播放;我正在尝试使用Flutter编写移动版本.我知道dart:web_audio是Web应用程序的主要选项,但是Flutter在我的SDK中找不到它.我知道它在那里,因为我可以将以下内容编译为Javascript:
import 'dart:HTML'; import 'dart:convert'; import 'dart:web_audio'; AudioContext audioContext; main() async { audioContext = new AudioContext(); var ul = (querySelector('#songs') as UListElement); var signal = await httpRequest.getString('http://10.0.0.6:8000/API/fileList'); // Map Json = JsON.decode(signal); // for (Map file in Json['songs']) { print("signal: $signal"); Map Json = JsON.decode(signal); for (Map file in Json['songs']) { var li = new LIElement() ..appendText(file['Title']); var button = new buttonElement(); button.setAttribute("ID", "#${file['file']}"); button.appendText("Play"); li.append(button); new Song(button, file['file']); ul.append(li); } } class Song { buttonElement button; bool _playing = false; // AudioContext _audioContext; AudioBufferSourceNode _source; String Title; Song(this.button, this.Title) { button..onClick.Listen((e) => _toggle()); } _toggle() { _playing = !_playing; _playing ? _start() : _stop(); } _start() { return httpRequest .request("http://10.0.0.6:8000/music/$Title", responseType: "arraybuffer") .then((httpRequest httpRequest) { return audioContext .decodeAudioData(httpRequest.response) .then((AudioBuffer buffer) { _source = audioContext.createBufferSource(); _source.buffer = buffer; _source.connectNode(audioContext.destination); _source.start(0); button.text = "Stop"; _source.onEnded.Listen((e){ _playing = false; button.text = "Play"; }); }); }); } _stop() { _source.stop(0); button.text = "Play"; } } 如何为Flutter应用程序重写代码中的dart:web_audio部分? Flutter可以访问MediaPlayer吗?如果是这样,我将如何在pubspec.yaml中引用它?
解决方法:
正如上面提到的raju-bitter一样,Flutter曾经在其核心引擎中提供了一些内置的音频包装器,但是后来被删除了:https://github.com/flutter/flutter/issues/1364.
使用Flutter的应用程序只是iOS或AndroID应用程序,因此可以使用hello_services模型(https://github.com/flutter/flutter/tree/master/examples/hello_services)中的某些Java或Obj-C代码通过Flutter完成底层iOS / AndroID可以执行的任何 *** 作.该模型记录在https://flutter.io/platform-services.它还没有我们想要的那么容易.许多改进即将推出.
总结以上是内存溢出为你收集整理的android-如何在Flutter应用中播放.mp3文件?全部内容,希望文章能够帮你解决android-如何在Flutter应用中播放.mp3文件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)