Skip to content

Commit

Permalink
Implement example
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguon Pisey authored and Nguon Pisey committed Dec 23, 2021
1 parent f01962d commit caaed8b
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .idea/misc.xml

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

4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}

buildFeatures{
viewBinding = true
}
}

dependencies {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PlayerOfflineActivity"
android:configChanges="orientation|screenSize|layoutDirection"
android:exported="false" />
</application>

</manifest>
44 changes: 42 additions & 2 deletions app/src/main/java/com/example/mediaplayer/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
package com.example.mediaplayer

import androidx.appcompat.app.AppCompatActivity
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.example.customexoplayer.PlayerResource
import com.example.customexoplayer.SubtitleModel
import com.example.customexoplayer.components.player.media.DownloadState
import com.example.mediaplayer.databinding.ActivityMainBinding


class MainActivity : AppCompatActivity() {
private lateinit var mBinding: ActivityMainBinding
@SuppressLint("WrongConstant")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(mBinding.root)
val mediaUrl = "https://d2cqvl54b1gtkt.cloudfront.net/PRODUCTION/5d85da3fa81ada4c66211a07/post/media/video/1616987127933-bfc1a13a-49c6-4272-8ffd-dc04b05eed2c/1616987128057-740d153b431660cf976789c1901192a961f0fd5b2a2af43e2388f671fa03c2aa/1616987128057-740d153b431660cf976789c1901192a961f0fd5b2a2af43e2388f671fa03c2aa.m3u8"
val subtitles = ArrayList<SubtitleModel>()
subtitles.add(SubtitleModel(subtitleUrl = "https://filebin.net/dr73cv9evxoquhqo/English_Transformers_The_Last_Knight_Official_Trailer_1_2017_Michael.srt",language = "English"))
subtitles.add(SubtitleModel(subtitleUrl = "https://filebin.net/dr73cv9evxoquhqo/Khmer_Transformers_The_Last_Knight_Official_Trailer_1_2017_Michael.srt",language = "Khmer"))
val playerResource = PlayerResource(mediaName = "Transformer",mediaUrl = mediaUrl,subtitles = subtitles)

mBinding.androidPlayer
.setPlayerResource(playerResource)
.setLifecycle(lifecycle)
.addDownloadListener(object: DownloadState {
override fun onDownloadCompleted(playerResource: PlayerResource) {
mBinding.btnPlayOffline.visibility = View.VISIBLE
}

override fun onDownloadStarted(playerResource: PlayerResource) {

}

override fun onDownloadFailed(playerResource: PlayerResource) {

}

override fun onVideoHasBeenDownloaded(playerResource: PlayerResource) {
mBinding.btnPlayOffline.visibility = View.VISIBLE
}

})
.buildOnline()
mBinding.btnPlayOffline.setOnClickListener {
startActivity(Intent(this, PlayerOfflineActivity::class.java))
}
}
}
28 changes: 28 additions & 0 deletions app/src/main/java/com/example/mediaplayer/PlayerOfflineActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.mediaplayer

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.customexoplayer.PlayerResource
import com.example.customexoplayer.SubtitleModel
import com.example.mediaplayer.databinding.ActivityPlayerOfflineBinding


class PlayerOfflineActivity : AppCompatActivity() {
lateinit var mBinding:ActivityPlayerOfflineBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = ActivityPlayerOfflineBinding.inflate(layoutInflater)
setContentView(mBinding.root)
val mediaUrl = "https://d2cqvl54b1gtkt.cloudfront.net/PRODUCTION/5d85da3fa81ada4c66211a07/post/media/video/1616987127933-bfc1a13a-49c6-4272-8ffd-dc04b05eed2c/1616987128057-740d153b431660cf976789c1901192a961f0fd5b2a2af43e2388f671fa03c2aa/1616987128057-740d153b431660cf976789c1901192a961f0fd5b2a2af43e2388f671fa03c2aa.m3u8"
val subtitles = ArrayList<SubtitleModel>()
subtitles.add(SubtitleModel(subtitleUrl = "https://filebin.net/dr73cv9evxoquhqo/English_Transformers_The_Last_Knight_Official_Trailer_1_2017_Michael.srt",language = "English"))
subtitles.add(SubtitleModel(subtitleUrl = "https://filebin.net/dr73cv9evxoquhqo/Khmer_Transformers_The_Last_Knight_Official_Trailer_1_2017_Michael.srt",language = "Khmer"))
val playerResource = PlayerResource(mediaName = "Transformer",mediaUrl = mediaUrl,subtitles = subtitles)

mBinding.androidPlayer
.setPlayerResource(playerResource)
.setShowButtonScreenType(true)
.setLifecycle(lifecycle)
.buildOffline()
}
}
30 changes: 18 additions & 12 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity"
android:orientation="vertical">

<com.example.customexoplayer.AndroidPlayer
android:id="@+id/androidPlayer"
app:resizingEnabled="true"
app:showButtonScreenType="true"
android:layout_width="match_parent"
android:layout_height="300dp"/>

<TextView
<Button
android:id="@+id/btnPlayOffline"
android:text="Play offline"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_height="wrap_content"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
15 changes: 15 additions & 0 deletions app/src/main/res/layout/activity_player_offline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".PlayerOfflineActivity">

<com.example.customexoplayer.AndroidPlayer
android:id="@+id/androidPlayer"
android:layout_width="match_parent"
android:layout_height="300dp"/>

</LinearLayout>

0 comments on commit caaed8b

Please sign in to comment.