43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
|
import 'package:freezer/api/definitions.dart';
|
||
|
import 'package:just_audio/just_audio.dart';
|
||
|
import 'package:http/http.dart' as http;
|
||
|
|
||
|
import 'deezer.dart';
|
||
|
|
||
|
class UrlAudioSource extends StreamAudioSource {
|
||
|
final Uri uri;
|
||
|
final StreamInfoCallback? onStreamObtained;
|
||
|
UrlAudioSource(this.uri, {this.onStreamObtained});
|
||
|
|
||
|
@override
|
||
|
Future<StreamAudioResponse> request([int? start, int? end]) async {
|
||
|
print('UrlAudioSource.request (uri: $uri) called!');
|
||
|
final req = http.Request('GET', uri)
|
||
|
..headers.addAll({
|
||
|
'User-Agent': deezerAPI.headers['User-Agent']!,
|
||
|
'Accept-Language': '*',
|
||
|
'Accept': '*/*',
|
||
|
if (start != null || end != null)
|
||
|
"Range": "bytes=" +
|
||
|
(start == null ? '' : start.toString()) +
|
||
|
"-" +
|
||
|
(end == null ? '' : end.toString())
|
||
|
});
|
||
|
|
||
|
final res = await req.send();
|
||
|
|
||
|
this.onStreamObtained?.call(StreamQualityInfo(
|
||
|
format: Format.MP3,
|
||
|
source: Source.stream,
|
||
|
quality: null,
|
||
|
size: res.contentLength! + (start ?? 0)));
|
||
|
|
||
|
return StreamAudioResponse(
|
||
|
sourceLength: res.contentLength! + (start ?? 0),
|
||
|
contentLength: res.contentLength!,
|
||
|
offset: start,
|
||
|
stream: res.stream,
|
||
|
contentType: res.headers['content-type']!);
|
||
|
}
|
||
|
}
|