using audio/mp4 for MacOS & iOS Platform for compatibilty

This commit is contained in:
Kingkor Roy Tirtho 2022-02-10 22:28:48 +06:00
parent 76fb153ff6
commit 88b201b24b
3 changed files with 14 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:collection/collection.dart';
import 'package:spotify/spotify.dart'; import 'package:spotify/spotify.dart';
import 'package:youtube_explode_dart/youtube_explode_dart.dart'; import 'package:youtube_explode_dart/youtube_explode_dart.dart';
@ -21,7 +23,16 @@ Future<Track> toYoutubeTrack(YoutubeExplode youtube, Track track) async {
var trackManifest = await youtube.videos.streams.getManifest(ytVideo.id); var trackManifest = await youtube.videos.streams.getManifest(ytVideo.id);
track.uri = trackManifest.audioOnly.withHighestBitrate().url.toString(); // Since Mac OS's & IOS's CodeAudio doesn't support WebMedia
// ('audio/webm', 'video/webm' & 'image/webp') thus using 'audio/mpeg'
// codec/mimetype for those Platforms
track.uri = (Platform.isMacOS || Platform.isIOS
? trackManifest.audioOnly
.where((info) => info.codec.mimeType == "audio/mp4")
.withHighestBitrate()
: trackManifest.audioOnly.withHighestBitrate())
.url
.toString();
track.href = ytVideo.url; track.href = ytVideo.url;
return track; return track;
} }

View File

@ -121,7 +121,7 @@ packages:
source: hosted source: hosted
version: "1.1.0" version: "1.1.0"
collection: collection:
dependency: transitive dependency: "direct main"
description: description:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"

View File

@ -49,6 +49,7 @@ dependencies:
just_audio_libwinmedia: ^0.0.4 just_audio_libwinmedia: ^0.0.4
path: ^1.8.0 path: ^1.8.0
path_provider: ^2.0.8 path_provider: ^2.0.8
collection: ^1.15.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: