Skip to content

Commit 234c8eb

Browse files
author
paroca72
committed
- Better coding
1 parent 92beebe commit 234c8eb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010
minSdkVersion 15
1111
targetSdkVersion 25
1212
versionCode 13
13-
versionName '1.0.2'
13+
versionName '1.0.3'
1414
vectorDrawables.useSupportLibrary = true
1515
}
1616
buildTypes {

library/src/main/java/com/sccomponents/playerbutton/ScPlayerButton.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,21 @@ private float dipToPixel(float dip) {
202202
* @return the duration in milliseconds
203203
*/
204204
private int getMediaDuration(String source) {
205+
MediaPlayer player = null;
205206
try {
206207
// Try to get the media duration
207-
MediaPlayer player = MediaPlayer.create(this.getContext(), Uri.parse(source));
208+
player = MediaPlayer.create(this.getContext(), Uri.parse(source));
208209
return player.getDuration();
209210

210211
} catch (Exception ex) {
211212
// Print the error on the stack and return
212213
ex.printStackTrace();
213214
return 0;
215+
216+
} finally {
217+
// Release the player
218+
if (player != null)
219+
player.release();
214220
}
215221
}
216222

0 commit comments

Comments
 (0)