7
7
import android .media .MediaPlayer ;
8
8
import android .net .Uri ;
9
9
import android .os .Build ;
10
- import android .util .Log ;
11
10
import com .huhx0015 .hxaudio .interfaces .HXMusicEngineListener ;
12
11
import com .huhx0015 .hxaudio .model .HXMusicItem ;
12
+ import com .huhx0015 .hxaudio .utils .HXLog ;
13
13
14
14
/** -----------------------------------------------------------------------------------------------
15
15
* [HXMusicEngine] CLASS
@@ -49,7 +49,7 @@ synchronized boolean initMusicEngine(HXMusicItem music, final int position, fina
49
49
50
50
// Stops any music currently playing in the background.
51
51
if (currentPlayer != null && currentPlayer .isPlaying ()) {
52
- Log .d (LOG_TAG , "PREPARING: initMusicEngine(): Song currently playing in the background. Stopping playback before switching to a new song." );
52
+ HXLog .d (LOG_TAG , "PREPARING: initMusicEngine(): Song currently playing in the background. Stopping playback before switching to a new song." );
53
53
currentPlayer .stop ();
54
54
}
55
55
@@ -67,7 +67,7 @@ public void onPrepared(MediaPlayer currentPlayer) {
67
67
68
68
if (musicPosition != 0 ) {
69
69
currentPlayer .seekTo (musicPosition );
70
- Log .d (LOG_TAG , "PREPARING: onPrepared(): MediaPlayer position set to: " + position );
70
+ HXLog .d (LOG_TAG , "PREPARING: onPrepared(): MediaPlayer position set to: " + position );
71
71
}
72
72
73
73
// GAPLESS: If gapless mode is enabled, the secondary MediaPlayer will begin
@@ -82,10 +82,10 @@ public void onPrepared(MediaPlayer currentPlayer) {
82
82
nextPlayer .setOnCompletionListener (nextPlayerCompletionListener );
83
83
nextPlayer .setOnBufferingUpdateListener (playerBufferingUpdateListener );
84
84
85
- Log .d (LOG_TAG , "PREPARING: Gapless mode prepared." );
85
+ HXLog .d (LOG_TAG , "PREPARING: Gapless mode prepared." );
86
86
} else {
87
87
currentPlayer .setLooping (isLooped ); // Sets the looping attribute.
88
- Log .d (LOG_TAG , "PREPARING: onPrepared(): MediaPlayer looping status: " + isLooped );
88
+ HXLog .d (LOG_TAG , "PREPARING: onPrepared(): MediaPlayer looping status: " + isLooped );
89
89
}
90
90
91
91
currentPlayer .start (); // Begins playing the music.
@@ -95,7 +95,7 @@ public void onPrepared(MediaPlayer currentPlayer) {
95
95
musicEngineListener .onMusicEnginePrepared ();
96
96
}
97
97
98
- Log .d (LOG_TAG , "MUSIC: onPrepared(): Music playback has begun." );
98
+ HXLog .d (LOG_TAG , "MUSIC: onPrepared(): Music playback has begun." );
99
99
}
100
100
});
101
101
@@ -120,7 +120,7 @@ public void onCompletion(MediaPlayer mp) {
120
120
musicEngineListener .onMusicEngineCompletion ();
121
121
}
122
122
123
- Log .d (LOG_TAG , "MUSIC: onCompletion(): Music playback has completed." );
123
+ HXLog .d (LOG_TAG , "MUSIC: onCompletion(): Music playback has completed." );
124
124
}
125
125
}
126
126
});
@@ -133,7 +133,7 @@ public void onCompletion(MediaPlayer mp) {
133
133
134
134
return true ;
135
135
} else {
136
- Log .e (LOG_TAG , "ERROR: initMusicEngine(): An error occurred while preparing the MediaPlayer object." );
136
+ HXLog .e (LOG_TAG , "ERROR: initMusicEngine(): An error occurred while preparing the MediaPlayer object." );
137
137
return false ;
138
138
}
139
139
}
@@ -145,16 +145,16 @@ private MediaPlayer prepareMediaPlayer(Context context) {
145
145
// Sets up the MediaPlayer object for the music to be played.
146
146
MediaPlayer player = new MediaPlayer (); // Initializes the MediaPlayer.
147
147
player .setAudioStreamType (AudioManager .STREAM_MUSIC ); // Sets the audio type for the MediaPlayer object.
148
- Log .d (LOG_TAG , "PREPARING: prepareMediaPlayer(): MediaPlayer stream type set to STREAM_MUSIC." );
148
+ HXLog .d (LOG_TAG , "PREPARING: prepareMediaPlayer(): MediaPlayer stream type set to STREAM_MUSIC." );
149
149
150
150
// Prepares the specified music URL for playback.
151
151
if (musicItem .getMusicUrl () != null ) {
152
152
try {
153
153
player .setDataSource (context , Uri .parse (musicItem .getMusicUrl ()));
154
154
player .prepareAsync (); // Prepares the MediaPlayer object asynchronously.
155
- Log .d (LOG_TAG , "PREPARING: prepareMediaPlayer(): MediaPlayer URL was set, preparing MediaPlayer..." );
155
+ HXLog .d (LOG_TAG , "PREPARING: prepareMediaPlayer(): MediaPlayer URL was set, preparing MediaPlayer..." );
156
156
} catch (Exception e ) {
157
- Log .e (LOG_TAG , "ERROR: prepareMediaPlayer(): An error occurred while loading the music from the specified URL: " + e .getLocalizedMessage ());
157
+ HXLog .e (LOG_TAG , "ERROR: prepareMediaPlayer(): An error occurred while loading the music from the specified URL: " + e .getLocalizedMessage ());
158
158
}
159
159
}
160
160
@@ -164,9 +164,9 @@ else if (musicItem.getMusicResource() != 0) {
164
164
AssetFileDescriptor asset = context .getResources ().openRawResourceFd (musicItem .getMusicResource ());
165
165
player .setDataSource (asset .getFileDescriptor (), asset .getStartOffset (), asset .getLength ());
166
166
player .prepareAsync (); // Prepares the MediaPlayer object asynchronously.
167
- Log .d (LOG_TAG , "PREPARING: prepareMediaPlayer(): MediaPlayer resource was set, preparing MediaPlayer..." );
167
+ HXLog .d (LOG_TAG , "PREPARING: prepareMediaPlayer(): MediaPlayer resource was set, preparing MediaPlayer..." );
168
168
} catch (Exception e ) {
169
- Log .e (LOG_TAG , "ERROR: prepareMediaPlayer(): An error occurred while loading the music resource: " + e .getLocalizedMessage ());
169
+ HXLog .e (LOG_TAG , "ERROR: prepareMediaPlayer(): An error occurred while loading the music resource: " + e .getLocalizedMessage ());
170
170
}
171
171
}
172
172
@@ -195,7 +195,7 @@ public void onCompletion(MediaPlayer mp) {
195
195
nextPlayer = prepareMediaPlayer (context ); // Prepares the next MediaPlayer.
196
196
nextPlayer .setOnPreparedListener (nextPlayerPreparedListener );
197
197
mp .release (); // Releases the previous MediaPlayer.
198
- Log .d (LOG_TAG , "MUSIC: onCompletion(): Preparing next MediaPlayer object for gapless playback." );
198
+ HXLog .d (LOG_TAG , "MUSIC: onCompletion(): Preparing next MediaPlayer object for gapless playback." );
199
199
}
200
200
};
201
201
@@ -210,7 +210,7 @@ public void onBufferingUpdate(MediaPlayer mp, int percent) {
210
210
musicEngineListener .onMusicEngineBufferingUpdate (percent );
211
211
}
212
212
213
- Log .d (LOG_TAG , "MUSIC: initMusicEngine(): Music buffering at: " + percent );
213
+ HXLog .d (LOG_TAG , "MUSIC: initMusicEngine(): Music buffering at: " + percent );
214
214
}
215
215
};
216
216
@@ -239,12 +239,12 @@ int pauseMusic() {
239
239
musicEngineListener .onMusicEnginePause ();
240
240
}
241
241
242
- Log .d (LOG_TAG , "MUSIC: pauseMusic(): Music playback has been paused." );
242
+ HXLog .d (LOG_TAG , "MUSIC: pauseMusic(): Music playback has been paused." );
243
243
return musicPosition ;
244
244
}
245
245
}
246
246
247
- Log .e (LOG_TAG , "ERROR: pauseMusic(): Music could not be paused." );
247
+ HXLog .e (LOG_TAG , "ERROR: pauseMusic(): Music could not be paused." );
248
248
return 0 ;
249
249
}
250
250
@@ -256,10 +256,10 @@ boolean release() {
256
256
currentPlayer .release ();
257
257
currentPlayer = null ;
258
258
259
- Log .d (LOG_TAG , "RELEASE: release(): MediaPlayer object has been released." );
259
+ HXLog .d (LOG_TAG , "RELEASE: release(): MediaPlayer object has been released." );
260
260
return true ;
261
261
} else {
262
- Log .e (LOG_TAG , "ERROR: release(): MediaPlayer object is null and cannot be released." );
262
+ HXLog .e (LOG_TAG , "ERROR: release(): MediaPlayer object is null and cannot be released." );
263
263
return false ;
264
264
}
265
265
}
@@ -275,10 +275,10 @@ boolean stopMusic() {
275
275
musicEngineListener .onMusicEngineStop ();
276
276
}
277
277
278
- Log .d (LOG_TAG , "MUSIC: stopMusic(): Music playback has been stopped." );
278
+ HXLog .d (LOG_TAG , "MUSIC: stopMusic(): Music playback has been stopped." );
279
279
return true ;
280
280
} else {
281
- Log .e (LOG_TAG , "ERROR: stopMusic(): Cannot stop music, as MediaPlayer object is already null." );
281
+ HXLog .e (LOG_TAG , "ERROR: stopMusic(): Cannot stop music, as MediaPlayer object is already null." );
282
282
return false ;
283
283
}
284
284
}
0 commit comments