package
com.sangyn.videodownloader
import
android.app.DownloadManager
import
android.content.Context
import
android.widget.MediaController
import
android.net.Uri
import
androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.widget.Button
import
android.widget.Toast
import
android.widget.VideoView
class
MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super
.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val videoView = findViewById<VideoView>(R.id.video_view)
val mediaController = MediaController(
this
)
videoView.setVideoURI(Uri.parse(url))
videoView.setMediaController(mediaController)
mediaController.setAnchorView(videoView)
videoView.start()
val downloadButton = findViewById<Button>(R.id.download)
downloadButton.setOnClickListener {
val download = applicationContext.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val videoUri = Uri.parse(url)
val getVideo = DownloadManager.Request(videoUri)
getVideo.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
download.enqueue(getVideo)
Toast.makeText(
this
,
"Download Started"
, Toast.LENGTH_LONG).show()
}
}
}