Skip to content

Commit a1f1ec0

Browse files
committed
library增加longPress处理,完善demo示例
1 parent 958f513 commit a1f1ec0

12 files changed

Lines changed: 100 additions & 15 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
android:icon="@mipmap/ic_launcher"
1919
android:label="@string/app_name"
2020
android:supportsRtl="true"
21+
android:usesCleartextTraffic="true"
2122
android:theme="@style/AppTheme">
2223
<activity
2324
android:name=".ui.SplashActivity"

app/src/main/java/com/kk/taurus/avplayer/bean/SettingItem.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class SettingItem {
2929

3030
public static final int CODE_VOLUME_SILENT = 600;
3131
public static final int CODE_VOLUME_RESET = 601;
32+
public static final int CODE_VOLUME_INCREASE = 602;
33+
public static final int CODE_VOLUME_REDUCE = 603;
3234

3335
public static final int CODE_CONTROLLER_REMOVE = 700;
3436
public static final int CODE_CONTROLLER_RESET = 701;
@@ -87,6 +89,9 @@ public static List<SettingItem> initSettingList(){
8789
items.add(new SettingItem("静音",CODE_VOLUME_SILENT));
8890
items.add(new SettingItem("恢复声音",CODE_VOLUME_RESET));
8991

92+
items.add(new SettingItem("音量加",CODE_VOLUME_INCREASE));
93+
items.add(new SettingItem("音量减",CODE_VOLUME_REDUCE));
94+
9095
items.add(new SettingItem("移除Controller组件",CODE_CONTROLLER_REMOVE));
9196
items.add(new SettingItem("恢复Controller组件",CODE_CONTROLLER_RESET));
9297

app/src/main/java/com/kk/taurus/avplayer/cover/ControllerCover.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public int getCoverLevel() {
480480
}
481481

482482
@Override
483-
public void onSingleTapUp(MotionEvent event) {
483+
public void onSingleTapConfirmed(MotionEvent event) {
484484
if(!mGestureEnable)
485485
return;
486486
toggleController();

app/src/main/java/com/kk/taurus/avplayer/cover/GestureCover.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.view.WindowManager;
1414
import android.widget.ImageView;
1515
import android.widget.TextView;
16+
import android.widget.Toast;
1617

1718
import com.kk.taurus.avplayer.R;
1819
import com.kk.taurus.avplayer.play.DataInter;
@@ -241,13 +242,13 @@ public void onReceiverEvent(int eventCode, Bundle bundle) {
241242
}
242243

243244
@Override
244-
public void onSingleTapUp(MotionEvent event) {
245+
public void onSingleTapConfirmed(MotionEvent event) {
245246

246247
}
247248

248249
@Override
249250
public void onLongPress(MotionEvent event) {
250-
251+
Toast.makeText(getContext(), "onLongPress", Toast.LENGTH_SHORT).show();
251252
}
252253

253254
@Override

app/src/main/java/com/kk/taurus/avplayer/ui/BaseVideoViewActivity.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public class BaseVideoViewActivity extends AppCompatActivity implements
5050
private RecyclerView mRecycler;
5151
private SettingAdapter mAdapter;
5252

53+
private float mVolumeLeft = 0.5f;
54+
private float mVolumeRight = 0.5f;
55+
5356
@Override
5457
protected void onCreate(@Nullable Bundle savedInstanceState) {
5558
super.onCreate(savedInstanceState);
@@ -73,7 +76,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
7376
mVideoView.setEventHandler(onVideoViewEventHandler);
7477
mVideoView.setOnPlayerEventListener(this);
7578

76-
// mVideoView.setVolume(0f, 0f);
79+
mVideoView.setVolume(mVolumeLeft, mVolumeRight);
7780
}
7881

7982
private void initPlay(){
@@ -218,6 +221,20 @@ public void onItemClick(SettingAdapter.SettingItemHolder holder, SettingItem ite
218221
case SettingItem.CODE_VOLUME_RESET:
219222
mVideoView.setVolume(1f, 1f);
220223
break;
224+
case SettingItem.CODE_VOLUME_INCREASE:
225+
mVolumeLeft += 0.1f;
226+
mVolumeRight += 0.1f;
227+
mVolumeLeft = Math.min(mVolumeLeft, 1f);
228+
mVolumeRight = Math.min(mVolumeRight, 1f);
229+
mVideoView.setVolume(mVolumeLeft, mVolumeRight);
230+
break;
231+
case SettingItem.CODE_VOLUME_REDUCE:
232+
mVolumeLeft -= 0.1f;
233+
mVolumeRight -= 0.1f;
234+
mVolumeLeft = Math.max(mVolumeLeft, 0f);
235+
mVolumeRight = Math.max(mVolumeRight, 0f);
236+
mVideoView.setVolume(mVolumeLeft, mVolumeRight);
237+
break;
221238
case SettingItem.CODE_CONTROLLER_REMOVE:
222239
mReceiverGroup.removeReceiver(DataInter.ReceiverKey.KEY_CONTROLLER_COVER);
223240
Toast.makeText(this, "已移除", Toast.LENGTH_SHORT).show();

app/src/main/java/com/kk/taurus/avplayer/ui/MusicPlayActivity.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.kk.taurus.avplayer.view.VisualizerView;
1717
import com.kk.taurus.playerbase.AVPlayer;
1818
import com.kk.taurus.playerbase.entity.DataSource;
19+
import com.kk.taurus.playerbase.event.OnErrorEventListener;
1920
import com.kk.taurus.playerbase.event.OnPlayerEventListener;
2021

2122
public class MusicPlayActivity extends AppCompatActivity implements OnPlayerEventListener {
@@ -33,6 +34,9 @@ public class MusicPlayActivity extends AppCompatActivity implements OnPlayerEven
3334

3435
private int typeIndex;
3536

37+
private float mVolumeLeft = 0.5f;
38+
private float mVolumeRight = 0.5f;
39+
3640
@Override
3741
protected void onCreate(@Nullable Bundle savedInstanceState) {
3842
super.onCreate(savedInstanceState);
@@ -43,7 +47,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4347
setVolumeControlStream(AudioManager.STREAM_MUSIC);
4448

4549
mPlayer = new AVPlayer();
50+
mPlayer.setVolume(mVolumeLeft, mVolumeRight);
4651
mPlayer.setOnPlayerEventListener(this);
52+
mPlayer.setOnErrorEventListener(new OnErrorEventListener() {
53+
@Override
54+
public void onErrorEvent(int eventCode, Bundle bundle) {
55+
Toast.makeText(MusicPlayActivity.this, "error:" + (bundle!=null?bundle.toString():""), Toast.LENGTH_SHORT).show();
56+
}
57+
});
4758

4859
initMusicWave();
4960
}
@@ -108,6 +119,22 @@ public void startPlay(View view){
108119
mPlayer.start();
109120
}
110121

122+
public void volumeIncrease(View view){
123+
mVolumeLeft += 0.1f;
124+
mVolumeRight += 0.1f;
125+
mVolumeLeft = Math.min(mVolumeLeft, 1f);
126+
mVolumeRight = Math.min(mVolumeRight, 1f);
127+
mPlayer.setVolume(mVolumeLeft, mVolumeRight);
128+
}
129+
130+
public void volumeReduce(View view){
131+
mVolumeLeft -= 0.1f;
132+
mVolumeRight -= 0.1f;
133+
mVolumeLeft = Math.max(mVolumeLeft, 0f);
134+
mVolumeRight = Math.max(mVolumeRight, 0f);
135+
mPlayer.setVolume(mVolumeLeft, mVolumeRight);
136+
}
137+
111138
@Override
112139
protected void onDestroy() {
113140
super.onDestroy();

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@
2626
android:textColor="#FFFFFF"
2727
android:text="PLAY"/>
2828

29+
<Button
30+
android:layout_width="match_parent"
31+
android:layout_height="40dp"
32+
android:layout_marginTop="10dp"
33+
android:background="@color/colorPrimary"
34+
android:onClick="volumeIncrease"
35+
android:textSize="16sp"
36+
android:textColor="#FFFFFF"
37+
android:text="音量加"/>
38+
39+
<Button
40+
android:layout_width="match_parent"
41+
android:layout_height="40dp"
42+
android:layout_marginTop="10dp"
43+
android:background="@color/colorPrimary"
44+
android:onClick="volumeReduce"
45+
android:textSize="16sp"
46+
android:textColor="#FFFFFF"
47+
android:text="音量减"/>
48+
2949
<com.kk.taurus.avplayer.view.VisualizerView
3050
android:id="@+id/visualizerView"
3151
android:layout_width="match_parent"

build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ allprojects {
3131
task clean(type: Delete) {
3232
delete rootProject.buildDir
3333
}
34+
35+
project.ext {
36+
37+
lib = [
38+
//module versions
39+
ijksdkVersion = '0.8.8',
40+
exoplayersdkVersion = '2.11.7',
41+
appcompatVersion = '1.1.0',
42+
playerbaseVersion = '3.3.6'
43+
]
44+
45+
}

exoplayer/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ android {
3030
dependencies {
3131
implementation fileTree(include: ['*.jar'], dir: 'libs')
3232

33-
api 'com.google.android.exoplayer:exoplayer-core:2.11.1'
34-
api 'com.google.android.exoplayer:exoplayer-dash:2.11.1'
35-
api 'com.google.android.exoplayer:exoplayer-hls:2.11.1'
36-
api 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.11.1'
37-
api 'com.kk.taurus.playerbase:playerbase:3.3.6'
38-
// api project(':playerbase')
33+
api "com.google.android.exoplayer:exoplayer-core:$exoplayersdkVersion"
34+
api "com.google.android.exoplayer:exoplayer-dash:$exoplayersdkVersion"
35+
api "com.google.android.exoplayer:exoplayer-hls:$exoplayersdkVersion"
36+
api "com.google.android.exoplayer:exoplayer-smoothstreaming:$exoplayersdkVersion"
37+
// api "com.kk.taurus.playerbase:playerbase:$playerbaseVersion"
38+
api project(':playerbase')
3939
}

ijkplayer/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ android {
3030
dependencies {
3131
implementation fileTree(include: ['*.jar'], dir: 'libs')
3232

33-
api 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
34-
api 'com.kk.taurus.playerbase:playerbase:3.3.6'
35-
// api project(':playerbase')
33+
api "tv.danmaku.ijk.media:ijkplayer-java:$ijksdkVersion"
34+
// api "com.kk.taurus.playerbase:playerbase:$playerbaseVersion"
35+
api project(':playerbase')
3636
}

0 commit comments

Comments
 (0)