From 3d401744c087536283a716b9d0f0dbd7bf01bee8 Mon Sep 17 00:00:00 2001 From: shabinder Date: Mon, 20 Jul 2020 00:58:44 +0530 Subject: [PATCH] Added a Workaround for downloading and saving Audio Files. Will improve on it soon! (Library needs Updation.) --- app/build.gradle | 4 ++-- app/src/main/AndroidManifest.xml | 1 + .../musicForEveryone/fragments/MainFragment.kt | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index acc3be5c..3682a22b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,7 +6,7 @@ apply plugin: "androidx.navigation.safeargs.kotlin" android { - compileSdkVersion 30 + compileSdkVersion 29 buildToolsVersion "30.0.0" buildFeatures{ @@ -17,7 +17,7 @@ android { defaultConfig { applicationId 'com.shabinder.musicforeveryone' minSdkVersion 22 - targetSdkVersion 30 + targetSdkVersion 29 versionCode 1 versionName "1.0" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index abd17598..44a5b960 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,6 +17,7 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" + android:requestLegacyExternalStorage="true" android:theme="@style/AppTheme"> diff --git a/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt b/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt index 88f21692..9f60aef4 100644 --- a/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt +++ b/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt @@ -1,6 +1,7 @@ package com.shabinder.musicForEveryone.fragments import android.os.Bundle +import android.os.Environment import android.util.Log import android.view.LayoutInflater import android.view.View @@ -10,6 +11,8 @@ import androidx.databinding.DataBindingUtil import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider +import com.github.kiulian.downloader.model.formats.Format +import com.github.kiulian.downloader.model.quality.AudioQuality import com.google.android.material.snackbar.Snackbar import com.shabinder.musicForEveryone.R import com.shabinder.musicForEveryone.SharedViewModel @@ -17,6 +20,7 @@ import com.shabinder.musicForEveryone.bindImage import com.shabinder.musicForEveryone.databinding.MainFragmentBinding import com.shabinder.musicForEveryone.utils.YoutubeConnector import kaaes.spotify.webapi.android.SpotifyService +import java.io.File class MainFragment : Fragment() { @@ -103,6 +107,18 @@ class MainFragment : Fragment() { val ytDownloader = sharedViewModel.ytDownloader val video = ytDownloader?.getVideo(data.id) val details = video?.details() + + val outputDir = File(Environment.getExternalStorageDirectory().toString() + File.separator + "MyAudio") + val format:Format = video?.findAudioWithQuality(AudioQuality.low)?.get(0) as Format + val audioUrl = format.url() + if (audioUrl != null) { + Log.i("ytDownloader", audioUrl) + }else{Log.i("YT audio url is null", format.toString())} + + val file:File = video.download( format , outputDir) + + Log.i("YT File Path=> ", file.path) + Log.i("ytDownloader", details?.title()?:"Error") binding.name.text = details?.title() }