Encoding works I think, just need to save
This commit is contained in:
parent
897ae05c1a
commit
9be11ad95b
@ -3,11 +3,8 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.example.myapplication">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -1,33 +1,31 @@
|
||||
package com.example.myapplication
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.ContentResolver
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.FileUtils
|
||||
import android.provider.MediaStore
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.net.toUri
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.arthenica.ffmpegkit.FFmpegKit
|
||||
import com.arthenica.ffmpegkit.FFmpegKitConfig
|
||||
import com.arthenica.ffmpegkit.FFmpegSession
|
||||
import com.example.myapplication.databinding.ActivityMainBinding
|
||||
import com.example.myapplication.ui.compressing.CompressingAdapter
|
||||
import com.example.myapplication.ui.compressing.CompressingFragment
|
||||
import com.example.myapplication.ui.compressing.CompressingItem
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.arthenica.ffmpegkit.FFmpegKit
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.util.*
|
||||
@ -41,6 +39,17 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
||||
// VERIFY PERMISSIONS
|
||||
val permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
|
||||
1
|
||||
)
|
||||
}
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
@ -73,6 +82,9 @@ class MainActivity : AppCompatActivity() {
|
||||
val intent = Intent()
|
||||
.setType("*/*")
|
||||
.setAction(Intent.ACTION_GET_CONTENT)
|
||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
|
||||
|
||||
resultLauncher.launch(intent)
|
||||
|
||||
@ -91,24 +103,34 @@ class MainActivity : AppCompatActivity() {
|
||||
//grabs output from pressing files, used for grabbing URI
|
||||
private var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
|
||||
// There are no request codes
|
||||
val data: Uri? = result.data?.data
|
||||
|
||||
val contentResolver: ContentResolver = contentResolver
|
||||
val fileDescriptor = contentResolver.openFileDescriptor(data!!, "r")
|
||||
val fd = fileDescriptor?.fileDescriptor
|
||||
val inputStream = FileInputStream(fd)
|
||||
|
||||
val file = File(data.toString())
|
||||
Log.i("Tag", file.absolutePath)
|
||||
|
||||
val fu = com.example.myapplication.utils.FileUtils(this)
|
||||
|
||||
val test = "-i " + fu.getPath(data) + " -c:v libx264 -preset ultrafast -crf 28 -c:a aac -b:a 128k -movflags +faststart " + fu.getPath(data) + "_converted.mp4"
|
||||
FFmpegKit.execute(test)
|
||||
val inUri = FFmpegKitConfig.getSafParameterForRead(this, data)
|
||||
|
||||
|
||||
val cursor = contentResolver.query(data, null, null, null, null)
|
||||
|
||||
|
||||
val outputFile = File(this.filesDir, "output.mp4")
|
||||
|
||||
if(outputFile.createNewFile()) {
|
||||
Log.i("Tag", "File created")
|
||||
} else {
|
||||
Log.i("Tag", "File not created")
|
||||
}
|
||||
|
||||
|
||||
val outUri = FFmpegKitConfig.getSafParameter(this, outputFile.toUri(), "rw")
|
||||
|
||||
val command = "-i $inUri -c:v mpeg4 $outUri -y"
|
||||
val session = FFmpegKit.execute(command)
|
||||
|
||||
Log.i("Tag", Arrays.deepToString(session.arguments))
|
||||
Log.i("Tag", session.output)
|
||||
|
||||
|
||||
val cursor = contentResolver.query(data!!, null, null, null, null)
|
||||
|
||||
cursor?.moveToFirst()
|
||||
|
||||
@ -118,8 +140,6 @@ class MainActivity : AppCompatActivity() {
|
||||
compressingItems.add(CompressingItem(fileName!!, 0.0, fileDate))
|
||||
|
||||
adapter.notifyDataSetChanged()
|
||||
|
||||
Toast.makeText(applicationContext, data.toString(), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user