Skip to content

Commit 1690206

Browse files
committed
Changes
1 parent cb62796 commit 1690206

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

fileViewer/build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
plugins {
22
id 'com.android.library'
3+
id 'maven-publish'
4+
35
}
46

57
android {
@@ -24,6 +26,14 @@ android {
2426
sourceCompatibility JavaVersion.VERSION_1_8
2527
targetCompatibility JavaVersion.VERSION_1_8
2628
}
29+
30+
publishing {
31+
singleVariant('release') {
32+
withSourcesJar()
33+
withJavadocJar()
34+
}
35+
}
36+
2737
}
2838

2939
dependencies {
@@ -36,4 +46,17 @@ dependencies {
3646

3747
api 'com.github.barteksc:pdfium-android:1.9.0'
3848

49+
}
50+
51+
afterEvaluate {
52+
publishing {
53+
publications {
54+
release(MavenPublication) {
55+
groupId 'io.genemoz'
56+
artifactId 'fileviewer'
57+
version '0.1'
58+
from components.release
59+
}
60+
}
61+
}
3962
}

fileViewer/src/main/java/io/genemoz/fileviewer/audioView/CustomAudioPlayer.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@
1717
import io.genemoz.fileviewer.R;
1818

1919
public class CustomAudioPlayer extends RelativeLayout {
20-
2120
private ImageView playButton;
2221
private SeekBar positionBar;
2322
private TextView elapsedTimeLabel;
2423
private TextView remainingTimeLabel;
2524
private MediaPlayer mediaPlayer;
2625
private final Handler handler = new Handler();
26+
private Runnable updateSeekBarRunnable = new Runnable() {
27+
@Override
28+
public void run() {
29+
updateSeekBar();
30+
}
31+
};
2732

2833
public CustomAudioPlayer(Context context) {
2934
super(context);
@@ -58,7 +63,9 @@ private void init(Context context) {
5863
@Override
5964
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
6065
if (mediaPlayer != null && fromUser) {
61-
mediaPlayer.seekTo(progress);
66+
int duration = mediaPlayer.getDuration();
67+
int seek = (int) ((float) progress / 100.0 * (float) duration);
68+
mediaPlayer.seekTo(seek);
6269
}
6370
}
6471

@@ -91,21 +98,32 @@ public void play() {
9198
if (mediaPlayer != null) {
9299
mediaPlayer.start();
93100
playButton.setImageResource(R.drawable.ic_pause_audio_lib);
94-
updateSeekBar();
101+
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
102+
@Override
103+
public void onCompletion(MediaPlayer mp) {
104+
handler.removeCallbacks(updateSeekBarRunnable); // stop updating
105+
playButton.setImageResource(R.drawable.ic_play_audio_lib);
106+
positionBar.setProgress(0);
107+
elapsedTimeLabel.setText(formatTime(0));
108+
remainingTimeLabel.setText(formatTime(mediaPlayer.getDuration()));
109+
}
110+
});
111+
handler.post(updateSeekBarRunnable); // start updating
95112
}
96113
}
97114

98115
public void pause() {
99116
if (mediaPlayer != null) {
100117
mediaPlayer.pause();
101118
playButton.setImageResource(R.drawable.ic_play_audio_lib);
119+
handler.removeCallbacks(updateSeekBarRunnable); // stop updating
102120
}
103121
}
104122

105123
private void updateSeekBar() {
106124
if (mediaPlayer != null) {
107125
positionBar.setProgress(mediaPlayer.getCurrentPosition());
108-
handler.postDelayed(this::updateSeekBar, 1000);
126+
handler.postDelayed(updateSeekBarRunnable, 1000);
109127
elapsedTimeLabel.setText(formatTime(mediaPlayer.getCurrentPosition()));
110128
remainingTimeLabel.setText(formatTime(mediaPlayer.getDuration() - mediaPlayer.getCurrentPosition()));
111129
}
@@ -124,6 +142,7 @@ protected void onDetachedFromWindow() {
124142
if (mediaPlayer.isPlaying()) {
125143
mediaPlayer.stop();
126144
}
145+
handler.removeCallbacks(updateSeekBarRunnable); // stop updating
127146
mediaPlayer.release();
128147
mediaPlayer = null;
129148
}

0 commit comments

Comments
 (0)