Flutter:如何在不带mp3扩展名的情况下流式传输由http URL提供的实时音频 [英] Flutter: How to stream live audio provided by a http url without mp3 extension
本文介绍了Flutter:如何在不带mp3扩展名的情况下流式传输由http URL提供的实时音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不带mp3扩展名的情况下流式传输由http URL提供的实时音频?它不是一个远程文件,但像webradio这样的流URL
How to stream live audio provided by a http url without mp3 extension with flutter? it's not a remote file, but a streaming url like a webradio
推荐答案
您可以使用包 https://pub.dev/packages/url_audio_stream
github https://github.com/tcronis/url_audio_stream
You can use package https://pub.dev/packages/url_audio_stream
github https://github.com/tcronis/url_audio_stream
代码段
AudioStream stream = new AudioStream("https://your_url_goes_here.com");
stream.start();
stream.pause();
stream.resume();
stream.stop();
完整的示例代码
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:url_audio_stream/url_audio_stream.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
}
static AudioStream stream = new AudioStream("your url");
Future<void> callAudio(String action) async{
if(action == "start"){
stream.start();
}else if(action == "stop"){
stream.stop();
}else if(action == "pause"){
stream.pause();
}else{
stream.resume();
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: <Widget>[
new RaisedButton(
child: new Text("Start"),
onPressed: (){
callAudio("start");
},
),
new RaisedButton(
child: new Text("Stop"),
onPressed: (){
callAudio("stop");
},
),
new RaisedButton(
child: new Text("Pause"),
onPressed: (){
callAudio("pause");
},
),
new RaisedButton(
child: new Text("Resume"),
onPressed: (){
callAudio("resume");
},
)
],
)
),
),
);
}
}
这篇关于Flutter:如何在不带mp3扩展名的情况下流式传输由http URL提供的实时音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文