Pato05
950969b774
add favorite button in notifications\nfix android tv\ntry to fix library tracks (unsuccessful)\nbetter MenuSheet
40 lines
1.2 KiB
Dart
40 lines
1.2 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 {
|
|
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();
|
|
|
|
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']!);
|
|
}
|
|
}
|