Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deletion shield: Android gradle plugin #48

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions mesh/android/ExoPlayerMeshPlugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions mesh/android/ExoPlayerMeshPlugin/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
50 changes: 50 additions & 0 deletions mesh/android/ExoPlayerMeshPlugin/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import lumen.DeliveryClientGradlePlugin

plugins {
id 'com.android.application'
id 'kotlin-android'
}

apply plugin: DeliveryClientGradlePlugin

android {
compileSdk 31

defaultConfig {
applicationId "io.streamroot.ctl.delivery.client.mesh.exoplayermesh"
minSdk 19
targetSdk 31
versionCode 1
versionName "1.0"
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
viewBinding true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
implementation "androidx.multidex:multidex:2.0.1"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation "com.google.android.exoplayer:exoplayer:2.16.1"
}
2 changes: 2 additions & 0 deletions mesh/android/ExoPlayerMeshPlugin/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-keep class io.streamroot.** { *; }
-dontwarn io.streamroot.lumen.**
36 changes: 36 additions & 0 deletions mesh/android/ExoPlayerMeshPlugin/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.streamroot.ctl.delivery.client.mesh.exoplayermesh">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ExoPlayerMesh"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:name=".Application">

<meta-data
android:name="io.streamroot.lumen.delivery.client.DeliveryClientKey"
android:value="demoswebsiteandpartners"
/>

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".PlayerActivity"
android:exported="false">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.streamroot.ctl.delivery.client.mesh.exoplayermesh

import androidx.multidex.MultiDexApplication
import io.streamroot.lumen.delivery.client.core.LumenDeliveryClient

class Application : MultiDexApplication() {
override fun onCreate() {
super.onCreate()
LumenDeliveryClient.initializeApp(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.streamroot.ctl.delivery.client.mesh.exoplayermesh

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import io.streamroot.ctl.delivery.client.mesh.exoplayermesh.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ActivityMainBinding.inflate(layoutInflater).apply {
this.playButton.setOnClickListener {
startActivity(Intent(this@MainActivity, PlayerActivity::class.java))
}

setContentView(this.root)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package io.streamroot.ctl.delivery.client.mesh.exoplayermesh

import android.net.Uri
import android.os.Bundle
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.util.Util
import io.streamroot.ctl.delivery.client.mesh.exoplayermesh.databinding.ActivityPlayerBinding
import io.streamroot.lumen.delivery.client.core.LumenLogLevel
import io.streamroot.lumen.delivery.client.plugin.LumenDeliveryClientPlugin
import io.streamroot.lumen.delivery.client.utils.LumenStatsView

class PlayerActivity : AppCompatActivity() {
private lateinit var bindings: ActivityPlayerBinding
private var plugin: LumenDeliveryClientPlugin? = null

private val manifestUrl: String = "http://wowza-test-cloudfront.streamroot.io/liveOrigin/Sintel1/playlist.m3u8"

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
bindings = ActivityPlayerBinding.inflate(layoutInflater)
setContentView(bindings.root)
}

override fun onStart() {
super.onStart()
if (Util.SDK_INT > 23) {
initializePlayer()
}
}

override fun onResume() {
super.onResume()
if (Util.SDK_INT <= 23 || plugin == null) {
initializePlayer()
}
}

override fun onPause() {
if (Util.SDK_INT <= 23) {
releasePlayer()
}
super.onPause()
}

override fun onStop() {
if (Util.SDK_INT > 23) {
releasePlayer()
}
super.onStop()
}

private fun initializePlayer() {
if (plugin == null) {
LumenDeliveryClientPlugin.Builder(this, manifestUrl).meshOptions {
logLevel(LumenLogLevel.INFO)
}.start().apply {
plugin = this

bindings.playerView.player = exoPlayer
showStatsView(this)

exoPlayer.playWhenReady = true
exoPlayer.addMediaItem(MediaItem.fromUri(Uri.parse(finalUri)))
exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
exoPlayer.prepare()
}
}
}

private fun showStatsView(plugin: LumenDeliveryClientPlugin) {
bindings.statsviewContainer.apply {
removeAllViews()
val statsView = LumenStatsView(this@PlayerActivity)
plugin.addStateStatsListener(statsView)
statsView.showStats()
addView(statsView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
}
}

private fun releasePlayer() {
if (plugin == null) return

stopDeliveryClient()
}

private fun stopDeliveryClient() {
plugin?.stop()
plugin?.exoPlayer?.release()
plugin = null
}
}

Loading