Skip to content

Commit 55c1124

Browse files
committed
update exo player with custom controllers
1 parent bf36f0a commit 55c1124

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed

app/src/main/java/yankov/tsvetilian/watchit/Activities/PlayerActivity.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ public void onChanged(@Nullable WatchModel watch) {
7575

7676
private void playInit(WatchModel watch) {
7777
player = ExoPlayerFactory.newSimpleInstance(PlayerActivity.this, new DefaultTrackSelector());
78+
TextView videoTitle = playerView.findViewById(R.id.play_title);
79+
videoTitle.setText(watch.getPresentableName());
80+
81+
TextView videoFrom = playerView.findViewById(R.id.play_from);
82+
videoFrom.setText(String.format("Stream from: %s", watch.getSourceName()));
83+
84+
TextView videoSeason = playerView.findViewById(R.id.play_season_episode);
85+
86+
if (watch.getSeason() != null) {
87+
videoSeason.setText(watch.getSeason());
88+
} else {
89+
videoSeason.setVisibility(View.GONE);
90+
}
91+
92+
TextView videoDescription = playerView.findViewById(R.id.play_description);
93+
videoDescription.setText(watch.getDescription());
94+
95+
Picasso.get().load(watch.getPoster()).fit().into(((ImageView) playerView.findViewById(R.id.play_poster)));
7896

7997
playerView.setPlayer(player);
8098

app/src/main/res/layout/activity_player.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
app:resize_mode="fill"
1313
app:fastforward_increment="5000"
1414
app:rewind_increment="5000"
15+
app:controller_layout_id="@layout/player_controls"
1516
android:layout_width="match_parent"
1617
android:layout_height="match_parent" />
1718
</FrameLayout>
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<TextView
8+
android:id="@+id/play_title"
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"
11+
android:layout_marginStart="8dp"
12+
android:layout_marginTop="8dp"
13+
android:alpha="0.7"
14+
android:background="#CC000000"
15+
android:padding="4dp"
16+
android:text="Play Title"
17+
android:ellipsize="end"
18+
android:textAppearance="@style/TextAppearance.AppCompat.Title"
19+
android:textColor="@color/colorPrimary"
20+
app:layout_constraintStart_toStartOf="parent"
21+
app:layout_constraintTop_toTopOf="parent" />
22+
23+
<TextView
24+
android:id="@+id/play_season_episode"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:layout_marginTop="8dp"
28+
android:layout_marginEnd="8dp"
29+
android:alpha="0.7"
30+
android:background="#CC000000"
31+
android:ellipsize="end"
32+
android:padding="4dp"
33+
android:text="S1E2"
34+
android:textAppearance="@style/TextAppearance.AppCompat.Title"
35+
android:textColor="@color/colorPrimary"
36+
app:layout_constraintEnd_toEndOf="parent"
37+
app:layout_constraintTop_toTopOf="parent" />
38+
39+
<TextView
40+
android:id="@+id/play_from"
41+
android:layout_width="wrap_content"
42+
android:layout_height="wrap_content"
43+
android:layout_marginStart="8dp"
44+
android:layout_marginTop="4dp"
45+
android:alpha="0.7"
46+
android:background="#CC000000"
47+
android:ellipsize="end"
48+
android:padding="4dp"
49+
android:text="Play From: My PC"
50+
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
51+
android:textColor="@color/colorPrimary"
52+
app:layout_constraintStart_toStartOf="parent"
53+
app:layout_constraintTop_toBottomOf="@+id/play_title" />
54+
55+
<ImageView
56+
android:id="@id/exo_play"
57+
android:layout_width="80dp"
58+
android:layout_height="80dp"
59+
android:layout_marginStart="8dp"
60+
android:layout_marginTop="8dp"
61+
android:layout_marginEnd="8dp"
62+
android:layout_marginBottom="8dp"
63+
android:alpha="0.7"
64+
android:scaleType="fitCenter"
65+
android:background="#CC000000"
66+
android:src="@drawable/ic_play_24dp"
67+
app:layout_constraintBottom_toBottomOf="parent"
68+
app:layout_constraintEnd_toEndOf="parent"
69+
app:layout_constraintStart_toStartOf="parent"
70+
app:layout_constraintTop_toTopOf="parent" />
71+
72+
<ImageView
73+
android:id="@id/exo_pause"
74+
android:layout_width="80dp"
75+
android:layout_height="80dp"
76+
android:layout_marginStart="8dp"
77+
android:layout_marginTop="8dp"
78+
android:layout_marginEnd="8dp"
79+
android:layout_marginBottom="8dp"
80+
android:alpha="0.7"
81+
android:scaleType="fitCenter"
82+
android:background="#CC000000"
83+
android:src="@drawable/ic_pause_80dp"
84+
app:layout_constraintBottom_toBottomOf="@+id/constraintLayout"
85+
app:layout_constraintEnd_toEndOf="parent"
86+
app:layout_constraintStart_toStartOf="parent"
87+
app:layout_constraintTop_toTopOf="parent" />
88+
89+
90+
<android.support.constraint.ConstraintLayout
91+
android:id="@+id/constraintLayout"
92+
android:layout_width="match_parent"
93+
android:layout_height="wrap_content"
94+
android:background="#CC000000"
95+
app:layout_constraintBottom_toBottomOf="parent"
96+
app:layout_constraintEnd_toEndOf="parent"
97+
app:layout_constraintStart_toStartOf="parent">
98+
99+
<ImageView
100+
android:id="@+id/play_poster"
101+
android:layout_width="61dp"
102+
android:layout_height="80dp"
103+
android:layout_marginStart="6dp"
104+
android:layout_marginTop="6dp"
105+
android:layout_marginBottom="6dp"
106+
android:padding="2dp"
107+
android:src="@drawable/ic_android_black_24dp"
108+
app:layout_constraintBottom_toTopOf="@+id/exo_position"
109+
app:layout_constraintStart_toStartOf="parent"
110+
app:layout_constraintTop_toTopOf="@+id/constraintLayout" />
111+
112+
<TextView
113+
android:id="@+id/play_description"
114+
android:layout_width="0dp"
115+
android:layout_height="0dp"
116+
android:layout_marginStart="8dp"
117+
android:layout_marginTop="8dp"
118+
android:layout_marginEnd="8dp"
119+
android:layout_marginBottom="8dp"
120+
android:ellipsize="end"
121+
android:text="Some description"
122+
android:textColor="@color/colorPrimary"
123+
app:layout_constraintBottom_toTopOf="@+id/exo_progress"
124+
app:layout_constraintEnd_toEndOf="parent"
125+
app:layout_constraintStart_toEndOf="@+id/play_poster"
126+
app:layout_constraintTop_toTopOf="parent" />
127+
128+
<TextView
129+
android:id="@+id/exo_position"
130+
android:layout_width="wrap_content"
131+
android:layout_height="wrap_content"
132+
android:layout_marginStart="6dp"
133+
android:layout_marginBottom="12dp"
134+
android:text="Position"
135+
android:textColor="@color/colorPrimary"
136+
app:layout_constraintBottom_toBottomOf="parent"
137+
app:layout_constraintStart_toStartOf="parent" />
138+
139+
<com.google.android.exoplayer2.ui.DefaultTimeBar
140+
android:id="@id/exo_progress"
141+
android:layout_width="0dp"
142+
android:layout_height="26dp"
143+
android:layout_marginStart="8dp"
144+
android:layout_marginBottom="8dp"
145+
android:layout_weight="1"
146+
app:layout_constraintBottom_toBottomOf="parent"
147+
app:layout_constraintEnd_toEndOf="parent"
148+
app:layout_constraintEnd_toStartOf="@+id/exo_duration"
149+
app:layout_constraintStart_toEndOf="@+id/exo_position" />
150+
151+
<TextView
152+
android:id="@+id/exo_duration"
153+
android:layout_width="wrap_content"
154+
android:layout_height="wrap_content"
155+
android:layout_marginEnd="6dp"
156+
android:layout_marginBottom="12dp"
157+
android:text="Duration"
158+
android:textColor="@color/colorPrimary"
159+
app:layout_constraintBottom_toBottomOf="parent"
160+
app:layout_constraintEnd_toEndOf="parent" />
161+
162+
</android.support.constraint.ConstraintLayout>
163+
164+
</android.support.constraint.ConstraintLayout>

0 commit comments

Comments
 (0)