-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sheikh Haziq
committed
Jan 15, 2025
1 parent
44c460b
commit 38b1e7e
Showing
12 changed files
with
241 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,71 @@ | ||
import 'dart:async'; | ||
import 'package:gyawun/services/stream_client.dart'; | ||
import 'package:just_audio/just_audio.dart'; | ||
import 'package:youtube_explode_dart/youtube_explode_dart.dart'; | ||
|
||
class CustomAudioStream extends StreamAudioSource { | ||
late YoutubeExplode ytExplode; | ||
AudioOnlyStreamInfo? streamInfo; | ||
String videoId; | ||
String quality; | ||
|
||
CustomAudioStream(this.videoId, this.quality, {super.tag}) { | ||
ytExplode = YoutubeExplode(); | ||
} | ||
|
||
Future _loadStreamInfo() async { | ||
StreamManifest manifest = await ytExplode.videos.streamsClient | ||
.getManifest(videoId, requireWatchPage: false); | ||
|
||
List<AudioOnlyStreamInfo> streamInfos = manifest.audioOnly | ||
.sortByBitrate() | ||
.reversed | ||
.where((stream) => stream.container == StreamContainer.mp4) | ||
.toList(); | ||
|
||
int qualityIndex = quality == 'low' ? 0 : streamInfos.length - 1; | ||
streamInfo = streamInfos[qualityIndex]; | ||
} | ||
|
||
@override | ||
Future<StreamAudioResponse> request([int? start, int? end]) async { | ||
if (streamInfo == null) { | ||
await _loadStreamInfo(); | ||
} | ||
|
||
start ??= 0; | ||
int size = streamInfo!.bitrate.bitsPerSecond * 80; | ||
end ??= (streamInfo!.isThrottled | ||
? (start + size) | ||
: streamInfo!.size.totalBytes); | ||
if (end > streamInfo!.size.totalBytes) { | ||
end = streamInfo!.size.totalBytes; | ||
} | ||
final response = | ||
AudioStreamClient().getAudioStream(streamInfo, start: start, end: end); | ||
|
||
return StreamAudioResponse( | ||
sourceLength: streamInfo!.size.totalBytes, | ||
contentLength: end - start, | ||
offset: start, | ||
stream: response, | ||
contentType: streamInfo!.codec.type, | ||
); | ||
} | ||
} | ||
// import 'dart:async'; | ||
// import 'package:gyawun/services/stream_client.dart'; | ||
// import 'package:just_audio/just_audio.dart'; | ||
// import 'package:youtube_explode_dart/youtube_explode_dart.dart'; | ||
|
||
// mixin HlsStreamInfo on StreamInfo { | ||
// /// The tag of the audio stream related to this stream. | ||
// int? get audioItag => null; | ||
// } | ||
|
||
// class CustomAudioStream extends StreamAudioSource { | ||
// late YoutubeExplode ytExplode; | ||
// StreamInfo? streamInfo; | ||
// String videoId; | ||
// String quality; | ||
|
||
// CustomAudioStream(this.videoId, this.quality, {super.tag}) { | ||
// ytExplode = YoutubeExplode(); | ||
// } | ||
|
||
// Future _loadStreamInfo() async { | ||
// StreamManifest manifest = | ||
// await ytExplode.videos.streamsClient.getManifest(videoId); | ||
|
||
// List<AudioOnlyStreamInfo> streamInfos = manifest.audioOnly | ||
// .sortByBitrate() | ||
// .reversed | ||
// .where((stream) => stream.container == StreamContainer.mp4) | ||
// .toList(); | ||
|
||
// int qualityIndex = quality == 'low' ? 0 : streamInfos.length - 1; | ||
// streamInfo = streamInfos[qualityIndex]; | ||
// if (streamInfo!.fragments.isNotEmpty) { | ||
// print("Using DASH Fragmented Stream"); | ||
// } else if (streamInfo is HlsStreamInfo) { | ||
// print("Using HLS Stream"); | ||
// } else { | ||
// print("Using Normal Stream"); | ||
// } | ||
// print(streamInfo!.url.toString()); | ||
// } | ||
|
||
// @override | ||
// Future<StreamAudioResponse> request([int? start, int? end]) async { | ||
// if (streamInfo == null) { | ||
// await _loadStreamInfo(); | ||
// } | ||
|
||
// start ??= 0; | ||
|
||
// int size = 10379935; | ||
// end = start + size.clamp(0, streamInfo!.size.totalBytes - start); | ||
// // if (!streamInfo!.isThrottled) { | ||
|
||
// // } | ||
// // end ??= streamInfo!.size.totalBytes; | ||
// if (end > streamInfo!.size.totalBytes) { | ||
// end = streamInfo!.size.totalBytes; | ||
// } | ||
// print('$start-$end'); | ||
// final response = ytExplode.videos.streams.get(streamInfo!, start, end); | ||
|
||
// return StreamAudioResponse( | ||
// sourceLength: streamInfo!.size.totalBytes, | ||
// contentLength: null, | ||
// offset: null, | ||
// stream: response, | ||
// contentType: streamInfo!.codec.type, | ||
// ); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.