Skip to content

Commit 79b36ef

Browse files
committed
add example exoplayer
1 parent d090805 commit 79b36ef

15 files changed

+192
-500
lines changed

.idea/codeStyles/Project.xml

-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dbnavigator.xml

-456
This file was deleted.

.idea/jarRepositories.xml

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+3-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/build.gradle

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ android {
2323
}
2424
}
2525

26+
compileOptions {
27+
sourceCompatibility JavaVersion.VERSION_1_8
28+
targetCompatibility JavaVersion.VERSION_1_8
29+
}
30+
31+
kotlinOptions {
32+
jvmTarget = JavaVersion.VERSION_1_8
33+
}
2634
}
2735

2836
dependencies {
@@ -42,4 +50,6 @@ dependencies {
4250
implementation project(':drag')
4351

4452
implementation 'com.github.bumptech.glide:glide:4.10.0'
53+
54+
implementation 'com.google.android.exoplayer:exoplayer:2.10.4'
4555
}

example/src/main/AndroidManifest.xml

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.tuanhav95.example">
44

5+
<uses-permission android:name="android.permission.INTERNET" />
6+
57
<application
68
android:allowBackup="true"
79
android:icon="@mipmap/ic_launcher"
810
android:label="@string/app_name"
911
android:roundIcon="@mipmap/ic_launcher_round"
1012
android:supportsRtl="true"
13+
android:usesCleartextTraffic="true"
1114
android:theme="@style/AppTheme">
12-
<activity android:name="com.tuanhav95.example.CustomActivity"></activity>
13-
<activity android:name="com.tuanhav95.example.NormalActivity" />
1415
<activity android:name="com.tuanhav95.example.MainActivity">
1516
<intent-filter>
1617
<action android:name="android.intent.action.MAIN" />
1718

1819
<category android:name="android.intent.category.LAUNCHER" />
1920
</intent-filter>
2021
</activity>
22+
<activity android:name="com.tuanhav95.example.NormalActivity" />
23+
<activity android:name="com.tuanhav95.example.CustomActivity" />
24+
<activity android:name="com.tuanhav95.example.ExoPlayerActivity" />
2125
</application>
2226

2327
</manifest>

example/src/main/java/com/tuanhav95/example/CustomActivity.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import androidx.appcompat.app.AppCompatActivity
55
import com.tuanhav95.drag.DragView
66
import com.tuanhav95.drag.utils.toPx
77
import com.tuanhav95.example.fragment.BottomFragment
8-
import com.tuanhav95.example.fragment.TopFragment
8+
import com.tuanhav95.example.fragment.NormalTopFragment
99
import kotlinx.android.synthetic.main.activity_custom.*
1010
import kotlinx.android.synthetic.main.layout_bottom.*
1111
import kotlin.math.max
@@ -28,7 +28,7 @@ class CustomActivity : AppCompatActivity() {
2828

2929
})
3030

31-
supportFragmentManager.beginTransaction().add(R.id.frameTop, TopFragment()).commit()
31+
supportFragmentManager.beginTransaction().add(R.id.frameTop, NormalTopFragment()).commit()
3232
supportFragmentManager.beginTransaction().add(R.id.frameBottom, BottomFragment()).commit()
3333

3434
btnMax.setOnClickListener { dragView.maximize() }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.tuanhav95.example
2+
3+
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
import com.tuanhav95.drag.DragView
6+
import com.tuanhav95.drag.utils.toPx
7+
import com.tuanhav95.example.fragment.BottomFragment
8+
import com.tuanhav95.example.fragment.ExoPlayerTopFragment
9+
import kotlinx.android.synthetic.main.activity_custom.*
10+
import kotlinx.android.synthetic.main.layout_bottom.*
11+
import kotlin.math.max
12+
import kotlin.math.min
13+
14+
class ExoPlayerActivity : AppCompatActivity() {
15+
16+
override fun onCreate(savedInstanceState: Bundle?) {
17+
super.onCreate(savedInstanceState)
18+
setContentView(R.layout.activity_custom)
19+
20+
dragView.setDragListener(object : DragView.DragListener {
21+
override fun onChangeState(state: DragView.State) {
22+
}
23+
24+
override fun onChangePercent(percent: Float) {
25+
alpha.alpha = 1 - percent
26+
shadow.alpha = percent
27+
}
28+
29+
})
30+
31+
supportFragmentManager.beginTransaction().add(R.id.frameTop, ExoPlayerTopFragment()).commit()
32+
supportFragmentManager.beginTransaction().add(R.id.frameBottom, BottomFragment()).commit()
33+
34+
btnMax.setOnClickListener { dragView.maximize() }
35+
btnMin.setOnClickListener { dragView.minimize() }
36+
btnClose.setOnClickListener { dragView.close() }
37+
38+
btnSetHeightMax.setOnClickListener {
39+
var heightMax = 0
40+
if (etHeightMax.text.isNotEmpty()) {
41+
heightMax = etHeightMax.text.toString().toInt()
42+
}
43+
heightMax = max(heightMax, 200)
44+
heightMax = min(heightMax, 400)
45+
46+
dragView.setHeightMax(heightMax.toPx(), true)
47+
}
48+
}
49+
}

example/src/main/java/com/tuanhav95/example/MainActivity.kt

+3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class MainActivity : AppCompatActivity() {
1212
setContentView(R.layout.activity_main)
1313

1414
btnNormal.setOnClickListener { startActivity(Intent(this, NormalActivity::class.java)) }
15+
1516
btnCustom.setOnClickListener { startActivity(Intent(this, CustomActivity::class.java)) }
1617

18+
btnExoplayer.setOnClickListener { startActivity(Intent(this, ExoPlayerActivity::class.java)) }
19+
1720
}
1821
}

example/src/main/java/com/tuanhav95/example/NormalActivity.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import androidx.appcompat.app.AppCompatActivity
44
import android.os.Bundle
55
import com.tuanhav95.drag.DragView
66
import com.tuanhav95.example.fragment.BottomFragment
7-
import com.tuanhav95.example.fragment.TopFragment
7+
import com.tuanhav95.example.fragment.NormalTopFragment
88
import kotlinx.android.synthetic.main.activity_normal.*
99

1010
class NormalActivity : AppCompatActivity() {
@@ -23,7 +23,7 @@ class NormalActivity : AppCompatActivity() {
2323

2424
})
2525

26-
supportFragmentManager.beginTransaction().add(R.id.frameFirst, TopFragment()).commit()
26+
supportFragmentManager.beginTransaction().add(R.id.frameFirst, NormalTopFragment()).commit()
2727
supportFragmentManager.beginTransaction().add(R.id.frameSecond, BottomFragment()).commit()
2828

2929
btnMax.setOnClickListener { dragView.maximize() }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.tuanhav95.example.fragment
2+
3+
import android.graphics.Color
4+
import android.net.Uri
5+
import android.os.Bundle
6+
import android.view.LayoutInflater
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import androidx.fragment.app.Fragment
10+
import com.google.android.exoplayer2.ExoPlayerFactory
11+
import com.google.android.exoplayer2.SimpleExoPlayer
12+
import com.google.android.exoplayer2.source.ProgressiveMediaSource
13+
import com.google.android.exoplayer2.upstream.DataSource
14+
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
15+
import com.google.android.exoplayer2.util.Util
16+
import com.tuanhav95.example.R
17+
import kotlinx.android.synthetic.main.fragment_top_exo_player.*
18+
19+
class ExoPlayerTopFragment : Fragment() {
20+
21+
companion object {
22+
const val STREAM_URL = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
23+
}
24+
25+
private lateinit var simpleExoPlayer: SimpleExoPlayer
26+
27+
private lateinit var mediaDataSourceFactory: DataSource.Factory
28+
29+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
30+
return inflater.inflate(R.layout.fragment_top_exo_player, container, false)
31+
}
32+
33+
override fun onActivityCreated(savedInstanceState: Bundle?) {
34+
super.onActivityCreated(savedInstanceState)
35+
36+
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context)
37+
38+
mediaDataSourceFactory = DefaultDataSourceFactory(context, Util.getUserAgent(context, "mediaPlayerSample"))
39+
40+
val mediaSource = ProgressiveMediaSource.Factory(mediaDataSourceFactory).createMediaSource(Uri.parse(STREAM_URL))
41+
42+
simpleExoPlayer.prepare(mediaSource, false, false)
43+
simpleExoPlayer.playWhenReady = true
44+
45+
playerView.setShutterBackgroundColor(Color.TRANSPARENT)
46+
playerView.player = simpleExoPlayer
47+
playerView.requestFocus()
48+
}
49+
50+
override fun onStop() {
51+
super.onStop()
52+
simpleExoPlayer.release()
53+
}
54+
55+
}

example/src/main/java/com/tuanhav95/example/fragment/TopFragment.kt example/src/main/java/com/tuanhav95/example/fragment/NormalTopFragment.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import android.view.ViewGroup
77
import androidx.fragment.app.Fragment
88
import com.tuanhav95.example.R
99

10-
class TopFragment: Fragment() {
10+
class NormalTopFragment: Fragment() {
1111
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
1212
return inflater.inflate(R.layout.fragment_top,container,false)
1313
}

example/src/main/res/layout/activity_main.xml

+5
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@
2222
android:layout_height="wrap_content"
2323
android:text="Custom" />
2424

25+
<Button
26+
android:id="@+id/btnExoplayer"
27+
android:layout_width="match_parent"
28+
android:layout_height="wrap_content"
29+
android:text="Exoplayer" />
2530
</LinearLayout>
2631
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/root"
4+
android:focusable="true"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:keepScreenOn="true">
8+
9+
<com.google.android.exoplayer2.ui.PlayerView
10+
android:id="@+id/playerView"
11+
android:focusable="true"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"/>
14+
15+
</FrameLayout>

0 commit comments

Comments
 (0)