Added a Workaround for downloading and saving Audio Files.

Will improve on it soon! (Library needs Updation.)
This commit is contained in:
shabinder 2020-07-20 00:58:44 +05:30
parent 8fcb22ab5d
commit 3d401744c0
3 changed files with 19 additions and 2 deletions

View File

@ -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"

View File

@ -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">
<activity android:name="com.shabinder.musicForEveryone.MainActivity">

View File

@ -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()
}