Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arezoonazer.androidvideoplayer">
xmlns:tools="http://schemas.android.com/tools"

package="com.arezoonazer.androidvideoplayer">
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<application
android:name=".PlayerApplication"
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.arezoonazer.androidvideoplayer

import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.widget.SeekBar
import android.widget.Toast
import android.widget.Toast.LENGTH_SHORT
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -14,6 +19,8 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

lateinit var skb_brightness: SeekBar

private val binding: ActivityMainBinding by lazy(LazyThreadSafetyMode.NONE) {
ActivityMainBinding.inflate(layoutInflater)
}
Expand All @@ -22,6 +29,14 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(binding.root)

skb_brightness = findViewById(R.id.seekBar)

Settings.System.putInt(
this.contentResolver,
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL
)

with(binding) {
playButton.setOnClickListener { startPlayer(getPlayerParam()) }

Expand All @@ -31,6 +46,27 @@ class MainActivity : AppCompatActivity() {

customPlayButton.setOnClickListener { onCustomPlayButtonClicked() }
}

skb_brightness.max = 255
skb_brightness.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {

override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
if (canWriteSettings) {

val lp = window.attributes
lp.screenBrightness = progress.toFloat() / 255
window.attributes = lp
} else {
startManageWriteSettingsPermission()
}
}

override fun onStartTrackingTouch(seekBar: SeekBar) {
}

override fun onStopTrackingTouch(seekBar: SeekBar) {
}
})
}

private fun getPlayerParam(): PlayerParams {
Expand Down Expand Up @@ -88,4 +124,38 @@ class MainActivity : AppCompatActivity() {
private fun showToast(message: String) {
Toast.makeText(this, message, LENGTH_SHORT).show()
}

private fun startManageWriteSettingsPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent(
Settings.ACTION_MANAGE_WRITE_SETTINGS,
Uri.parse("package:${this.packageName}")
).let {
startActivityForResult(it, 5)
}
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

when (requestCode) {
1 -> {
if (this.canWriteSettings) {
// change the settings here ...
} else {
Toast.makeText(
applicationContext,
"Write settings permission is not granted!",
Toast.LENGTH_SHORT
).show()
}
}
}
}

val canWriteSettings: Boolean
get() = Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.System.canWrite(this)


}
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,15 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/customPlayButton" />

<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="624dp"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="-16dp">
</SeekBar>


</androidx.constraintlayout.widget.ConstraintLayout>
20 changes: 19 additions & 1 deletion player/src/main/res/layout/exo_player_view.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="false"
Expand All @@ -20,7 +22,10 @@
<androidx.media3.ui.SubtitleView
android:id="@id/exo_subtitles"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent" >


</androidx.media3.ui.SubtitleView>

</androidx.media3.ui.AspectRatioFrameLayout>

Expand All @@ -33,6 +38,19 @@
android:id="@id/exo_controller_placeholder"
layout="@layout/exo_player_control_view" />

<SeekBar
android:id="@+id/seekBar"
android:layout_marginVertical="100dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="624dp"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="-16dp">
</SeekBar>



</FrameLayout>

</merge>