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"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="com.example.myapplication">
|
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_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.WRITE_INTERNAL_STORAGE"/>
|
||||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
@ -1,33 +1,31 @@
|
|||||||
package com.example.myapplication
|
package com.example.myapplication
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.Activity
|
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.FileUtils
|
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.net.toUri
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.navigation.ui.AppBarConfiguration
|
import androidx.navigation.ui.AppBarConfiguration
|
||||||
import androidx.navigation.ui.setupActionBarWithNavController
|
import androidx.navigation.ui.setupActionBarWithNavController
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import com.arthenica.ffmpegkit.FFmpegKit
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import com.arthenica.ffmpegkit.FFmpegKitConfig
|
||||||
|
import com.arthenica.ffmpegkit.FFmpegSession
|
||||||
import com.example.myapplication.databinding.ActivityMainBinding
|
import com.example.myapplication.databinding.ActivityMainBinding
|
||||||
import com.example.myapplication.ui.compressing.CompressingAdapter
|
import com.example.myapplication.ui.compressing.CompressingAdapter
|
||||||
import com.example.myapplication.ui.compressing.CompressingFragment
|
|
||||||
import com.example.myapplication.ui.compressing.CompressingItem
|
import com.example.myapplication.ui.compressing.CompressingItem
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
import com.arthenica.ffmpegkit.FFmpegKit
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -41,6 +39,17 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
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)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
@ -73,6 +82,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
.setType("*/*")
|
.setType("*/*")
|
||||||
.setAction(Intent.ACTION_GET_CONTENT)
|
.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)
|
resultLauncher.launch(intent)
|
||||||
|
|
||||||
@ -91,24 +103,34 @@ class MainActivity : AppCompatActivity() {
|
|||||||
//grabs output from pressing files, used for grabbing URI
|
//grabs output from pressing files, used for grabbing URI
|
||||||
private var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
private var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
if (result.resultCode == RESULT_OK) {
|
if (result.resultCode == RESULT_OK) {
|
||||||
|
|
||||||
// There are no request codes
|
// There are no request codes
|
||||||
val data: Uri? = result.data?.data
|
val data: Uri? = result.data?.data
|
||||||
|
|
||||||
val contentResolver: ContentResolver = contentResolver
|
val inUri = FFmpegKitConfig.getSafParameterForRead(this, data)
|
||||||
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 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()
|
cursor?.moveToFirst()
|
||||||
|
|
||||||
@ -118,8 +140,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
compressingItems.add(CompressingItem(fileName!!, 0.0, fileDate))
|
compressingItems.add(CompressingItem(fileName!!, 0.0, fileDate))
|
||||||
|
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
|
|
||||||
Toast.makeText(applicationContext, data.toString(), Toast.LENGTH_LONG).show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user