-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nguon Pisey
authored and
Nguon Pisey
committed
Dec 23, 2021
1 parent
f01962d
commit caaed8b
Showing
7 changed files
with
113 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,10 @@ android { | |
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
|
||
buildFeatures{ | ||
viewBinding = true | ||
} | ||
} | ||
|
||
dependencies { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
app/src/main/java/com/example/mediaplayer/PlayerOfflineActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |