├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── strings.xml
│ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ └── activity_camera_demo.xml
│ │ ├── drawable
│ │ │ ├── stop_icon.xml
│ │ │ ├── pause_icon.xml
│ │ │ ├── record_icon.xml
│ │ │ ├── stream_icon.xml
│ │ │ ├── stream_stop_icon.xml
│ │ │ ├── switch_icon.xml
│ │ │ └── ic_launcher_background.xml
│ │ └── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ └── com
│ │ │ └── pedro
│ │ │ └── sample
│ │ │ ├── Extensions.kt
│ │ │ ├── PathUtils.kt
│ │ │ ├── ScreenOrientation.kt
│ │ │ ├── MainActivity.kt
│ │ │ └── CameraDemoActivity.kt
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle.kts
├── jitpack.yml
├── rtspserver
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ └── java
│ │ └── com
│ │ └── pedro
│ │ └── rtspserver
│ │ ├── server
│ │ ├── IpType.kt
│ │ ├── ClientListener.kt
│ │ ├── ServerClient.kt
│ │ ├── ServerCommandManager.kt
│ │ └── RtspServer.kt
│ │ ├── socket
│ │ ├── ClientSocket.kt
│ │ ├── TcpStreamClientSocketJava.kt
│ │ ├── TcpStreamClientSocketKtor.kt
│ │ └── StreamServerSocket.kt
│ │ ├── util
│ │ ├── Extensions.kt
│ │ └── RtspServerStreamClient.kt
│ │ ├── RtspServerOnlyAudio.kt
│ │ ├── RtspServerDisplay.kt
│ │ ├── RtspServerCamera2.kt
│ │ ├── RtspServerStream.kt
│ │ ├── RtspServerFromFile.kt
│ │ └── RtspServerCamera1.kt
├── proguard-rules.pro
└── build.gradle.kts
├── gradle.properties
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── libs.versions.toml
├── .gitignore
├── README.md
├── settings.gradle.kts
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk17
--------------------------------------------------------------------------------
/rtspserver/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/rtspserver/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.enableJetifier=true
2 | android.useAndroidX=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/rtspserver/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | rtspserver
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedroSG94/RTSP-Server/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/
5 | /.idea/navEditor.xml
6 | /.idea/assetWizardSettings.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/rtspserver/src/main/java/com/pedro/rtspserver/server/IpType.kt:
--------------------------------------------------------------------------------
1 | package com.pedro.rtspserver.server
2 |
3 | /**
4 | * Created by pedro on 23/1/24.
5 | */
6 | enum class IpType {
7 | IPv4, IPv6, All
8 | }
--------------------------------------------------------------------------------
/rtspserver/src/main/java/com/pedro/rtspserver/socket/ClientSocket.kt:
--------------------------------------------------------------------------------
1 | package com.pedro.rtspserver.socket
2 |
3 | import com.pedro.common.socket.base.TcpStreamSocket
4 |
5 | data class ClientSocket(
6 | val host: String,
7 | val port: Int,
8 | val socket: TcpStreamSocket
9 | )
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 26 11:03:20 CEST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 | #e74c3c
7 | #000000
8 |
9 |
--------------------------------------------------------------------------------
/rtspserver/src/main/java/com/pedro/rtspserver/server/ClientListener.kt:
--------------------------------------------------------------------------------
1 | package com.pedro.rtspserver.server
2 |
3 | /**
4 | * Created by pedro on 20/12/23.
5 | */
6 | interface ClientListener {
7 |
8 | fun onClientConnected(client: ServerClient)
9 |
10 | fun onClientDisconnected(client: ServerClient)
11 |
12 | fun onClientNewBitrate(bitrate: Long, client: ServerClient)
13 | }
--------------------------------------------------------------------------------
/rtspserver/src/main/java/com/pedro/rtspserver/util/Extensions.kt:
--------------------------------------------------------------------------------
1 | package com.pedro.rtspserver.util
2 |
3 | import android.media.MediaCodec
4 | import com.pedro.common.frame.MediaFrame
5 | import com.pedro.common.isKeyframe
6 |
7 | /**
8 | * Created by pedro on 28/10/24.
9 | */
10 |
11 | fun MediaCodec.BufferInfo.toMediaFrameInfo(startTs: Long) = MediaFrame.Info(offset, size, presentationTimeUs - startTs, isKeyframe())
--------------------------------------------------------------------------------
/rtspserver/src/main/java/com/pedro/rtspserver/socket/TcpStreamClientSocketJava.kt:
--------------------------------------------------------------------------------
1 | package com.pedro.rtspserver.socket
2 |
3 | import com.pedro.common.socket.java.TcpStreamSocketJavaBase
4 | import java.net.Socket
5 |
6 | class TcpStreamClientSocketJava(
7 | private val socket: Socket
8 | ): TcpStreamSocketJavaBase() {
9 |
10 | override fun onConnectSocket(timeout: Long): Socket {
11 | return socket
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RTSPServer
3 | Start server
4 | Stop server
5 | Switch camera
6 | Start record
7 | Stop record
8 | Camera Demo
9 |
10 |
--------------------------------------------------------------------------------
/rtspserver/src/main/java/com/pedro/rtspserver/socket/TcpStreamClientSocketKtor.kt:
--------------------------------------------------------------------------------
1 | package com.pedro.rtspserver.socket
2 |
3 | import com.pedro.common.socket.ktor.TcpStreamSocketKtorBase
4 | import io.ktor.network.sockets.ReadWriteSocket
5 | import io.ktor.network.sockets.Socket
6 |
7 | class TcpStreamClientSocketKtor(
8 | private val socket: Socket,
9 | host: String, port: Int
10 | ): TcpStreamSocketKtorBase(host, port) {
11 |
12 | override suspend fun onConnectSocket(timeout: Long): ReadWriteSocket {
13 | return socket
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RTSP-Server
2 |
3 | [](https://jitpack.io/#pedroSG94/RTSP-Server)
4 |
5 | Plugin of RootEncoder to stream directly to RTSP player.
6 |
7 | ## Compile
8 |
9 | To use this library in your project with gradle add this to your build.gradle:
10 |
11 | ```gradle
12 | allprojects {
13 | repositories {
14 | maven { url 'https://jitpack.io' }
15 | }
16 | }
17 | dependencies {
18 | implementation 'com.github.pedroSG94:RTSP-Server:1.3.6'
19 | implementation 'com.github.pedroSG94.RootEncoder:library:2.6.1'
20 | }
21 |
22 | ```
23 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | }
8 | plugins {
9 | id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
10 | }
11 |
12 | @Suppress("UnstableApiUsage")
13 | dependencyResolutionManagement {
14 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
15 | repositories {
16 | google()
17 | mavenCentral()
18 | maven { url = uri("https://jitpack.io") }
19 | }
20 | }
21 |
22 | rootProject.name = "RTSP-Server"
23 | include(":app", ":rtspserver")
24 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/stop_icon.xml:
--------------------------------------------------------------------------------
1 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.kts.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/rtspserver/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.kts.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/pause_icon.xml:
--------------------------------------------------------------------------------
1 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/record_icon.xml:
--------------------------------------------------------------------------------
1 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pedro/sample/Extensions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 pedroSG94.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.pedro.sample
18 |
19 | import android.app.Activity
20 | import android.widget.Toast
21 |
22 | /**
23 | * Created by pedro on 1/3/24.
24 | */
25 |
26 | fun Activity.toast(message: String, duration: Int = Toast.LENGTH_SHORT) {
27 | Toast.makeText(this, message, duration).show()
28 | }
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | alias(libs.plugins.android.application)
3 | alias(libs.plugins.jetbrains.kotlin)
4 | }
5 |
6 | android {
7 | namespace = "com.pedro.sample"
8 | compileSdk = 36
9 |
10 | defaultConfig {
11 | applicationId = "com.pedro.sample"
12 | minSdk = 16
13 | targetSdk = 36
14 | versionCode = libs.versions.versionCode.get().toInt()
15 | versionName = libs.versions.versionName.get()
16 | }
17 | buildTypes {
18 | release {
19 | isMinifyEnabled = false
20 | proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
21 | }
22 | }
23 | compileOptions {
24 | sourceCompatibility = JavaVersion.VERSION_17
25 | targetCompatibility = JavaVersion.VERSION_17
26 | }
27 | kotlin {
28 | jvmToolchain(17)
29 | }
30 | }
31 |
32 | dependencies {
33 | implementation(project(":rtspserver"))
34 | implementation(libs.rootEncoder.library)
35 | implementation(libs.androidx.appcompat)
36 | implementation(libs.androidx.constraintlayout)
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
19 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/rtspserver/src/main/java/com/pedro/rtspserver/RtspServerOnlyAudio.kt:
--------------------------------------------------------------------------------
1 | package com.pedro.rtspserver
2 |
3 | import android.media.MediaCodec
4 | import com.pedro.common.AudioCodec
5 | import com.pedro.common.ConnectChecker
6 | import com.pedro.library.base.OnlyAudioBase
7 | import com.pedro.rtspserver.server.RtspServer
8 | import com.pedro.rtspserver.util.RtspServerStreamClient
9 | import java.nio.ByteBuffer
10 |
11 | /**
12 | * Created by pedro on 17/04/21.
13 | */
14 | class RtspServerOnlyAudio(
15 | connectChecker: ConnectChecker, port: Int
16 | ): OnlyAudioBase() {
17 |
18 | private val rtspServer = RtspServer(connectChecker, port).apply {
19 | setOnlyAudio(true)
20 | }
21 |
22 | fun startStream() {
23 | super.startStream("")
24 | }
25 |
26 | override fun onAudioInfoImp(isStereo: Boolean, sampleRate: Int) {
27 | rtspServer.setAudioInfo(sampleRate, isStereo)
28 | }
29 |
30 | override fun startStreamImp(url: String) {
31 | rtspServer.startServer()
32 | }
33 |
34 | override fun stopStreamImp() {
35 | rtspServer.stopServer()
36 | }
37 |
38 | override fun getAudioDataImp(audioBuffer: ByteBuffer, info: MediaCodec.BufferInfo) {
39 | rtspServer.sendAudio(audioBuffer, info)
40 | }
41 |
42 | override fun getStreamClient(): RtspServerStreamClient = RtspServerStreamClient(rtspServer)
43 |
44 | override fun setAudioCodecImp(codec: AudioCodec) {
45 | rtspServer.setAudioCodec(codec);
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/pedro/sample/PathUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 pedroSG94.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.pedro.sample
17 |
18 | import android.content.Context
19 | import android.media.MediaScannerConnection
20 | import android.os.Environment
21 | import java.io.File
22 |
23 | /**
24 | * Created by pedro on 21/06/17.
25 | * Get absolute path from onActivityResult
26 | * https://stackoverflow.com/questions/33295300/how-to-get-absolute-path-in-android-for-file
27 | */
28 | object PathUtils {
29 | @JvmStatic
30 | fun getRecordPath(): File {
31 | val storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
32 | return File(storageDir.absolutePath + "/RootEncoder")
33 | }
34 |
35 | @JvmStatic
36 | fun updateGallery(context: Context, path: String) {
37 | MediaScannerConnection.scanFile(context, arrayOf(path), null, null)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | libraryGroup = "com.github.pedroSG94"
3 | versionCode = "136"
4 | versionName = "1.3.6"
5 |
6 | #plugins versions
7 | agp = "8.11.0"
8 | kotlin = "2.2.0"
9 | dokka = "2.0.0"
10 |
11 | #dependencies versions
12 | #noinspection GradleDependency, version 1.7.0 need min sdk 21
13 | appcompat = "1.6.1"
14 | #noinspection GradleDependency, version 2.2.0 need min sdk 21
15 | constraintlayout = "2.1.4"
16 | coroutines = "1.10.2"
17 | ktor = "3.3.1"
18 | rootEncoder = "2.6.5"
19 |
20 | [libraries]
21 | androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
22 | androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }
23 | kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
24 | ktor-network = { module = "io.ktor:ktor-network", version.ref = "ktor" }
25 | ktor-network-tls = { module = "io.ktor:ktor-network-tls", version.ref = "ktor" }
26 | rootEncoder-library = { module = "com.github.pedroSG94.RootEncoder:library", version.ref = "rootEncoder" }
27 |
28 | [plugins]
29 | android-application = { id = "com.android.application", version.ref = "agp" }
30 | android-library = { id = "com.android.library", version.ref = "agp" }
31 | maven-publish = { id = "maven-publish", version.ref = "agp" }
32 | jetbrains-kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
33 | jetbrains-dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
--------------------------------------------------------------------------------
/app/src/main/java/com/pedro/sample/ScreenOrientation.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 pedroSG94.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.pedro.sample
18 |
19 | import android.app.Activity
20 | import android.content.pm.ActivityInfo
21 | import com.pedro.encoder.input.video.CameraHelper
22 |
23 | object ScreenOrientation {
24 | fun lockScreen(activity: Activity) {
25 | val currentOrientation = when (CameraHelper.getCameraOrientation(activity)) {
26 | 90 -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
27 | 180 -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
28 | 270 -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
29 | else -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
30 | }
31 | activity.requestedOrientation = currentOrientation
32 | }
33 |
34 | fun unlockScreen(activity: Activity) {
35 | activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
36 | }
37 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/pedro/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.pedro.sample
2 |
3 | import android.Manifest
4 | import android.content.Context
5 | import android.content.Intent
6 | import android.content.pm.PackageManager
7 | import android.os.Build
8 | import android.os.Bundle
9 | import android.view.WindowManager
10 | import android.widget.Button
11 | import androidx.appcompat.app.AppCompatActivity
12 | import androidx.core.app.ActivityCompat
13 |
14 | class MainActivity : AppCompatActivity() {
15 |
16 | private val permissions = arrayOf(Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA)
17 |
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
21 | setContentView(R.layout.activity_main)
22 | val bCameraDemo = findViewById