Closed Khattak11 closed 2 weeks ago
i download video from youtube to local storage but when the video is download it have not the audio here is my code :
void _downloadVideo(String url) async { await Permission.storage.request(); try { setState(() { isLoading = true; }); String? videoId = extractVideoId(url); if (videoId == null) { print("Invalid URL: Unable to extract video ID."); return; } var ytExplode = YoutubeExplode(); var video = await ytExplode.videos.get(videoId); videoTitle = video.title; var manifest = await ytExplode.videos.streamsClient.getManifest(videoId); var streamInfo = manifest.audioOnly.first; var videoStream = manifest.video.first; var audioStream = ytExplode.videos.streamsClient.get(streamInfo); var videoFile = ytExplode.videos.streamsClient.get(videoStream); print(video.title); _saveVideo(videoFile, videoStream.container.name); } catch (e) { print("....................." + e.toString()); } } void _saveVideo(Stream<List<int>> videoFile, String videoTitle) async { try { final appDocDir = await getDownloadsDirectory(); final savePath = appDocDir!.path + '/$videoTitle.mp4'; final file = File(savePath); final sink = file.openWrite(); // Use pipe to write the stream content to the file await videoFile.pipe(sink); await sink.close(); setState(() { isLoading = false; }); print("...................................saved$savePath"); } catch (e) { print("....................." + e.toString()); } }
You are not saving the audioStream anywhere, .video returns streams what have only videos without audio.
audioStream
.video
i download video from youtube to local storage but when the video is download it have not the audio here is my code :