77import android .media .MediaPlayer ;
88import android .net .Uri ;
99import android .os .Build ;
10- import android .util .Log ;
1110import com .huhx0015 .hxaudio .interfaces .HXMusicEngineListener ;
1211import com .huhx0015 .hxaudio .model .HXMusicItem ;
12+ import com .huhx0015 .hxaudio .utils .HXLog ;
1313
1414/** -----------------------------------------------------------------------------------------------
1515 * [HXMusicEngine] CLASS
@@ -49,7 +49,7 @@ synchronized boolean initMusicEngine(HXMusicItem music, final int position, fina
4949
5050 // Stops any music currently playing in the background.
5151 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." );
5353 currentPlayer .stop ();
5454 }
5555
@@ -67,7 +67,7 @@ public void onPrepared(MediaPlayer currentPlayer) {
6767
6868 if (musicPosition != 0 ) {
6969 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 );
7171 }
7272
7373 // GAPLESS: If gapless mode is enabled, the secondary MediaPlayer will begin
@@ -82,10 +82,10 @@ public void onPrepared(MediaPlayer currentPlayer) {
8282 nextPlayer .setOnCompletionListener (nextPlayerCompletionListener );
8383 nextPlayer .setOnBufferingUpdateListener (playerBufferingUpdateListener );
8484
85- Log .d (LOG_TAG , "PREPARING: Gapless mode prepared." );
85+ HXLog .d (LOG_TAG , "PREPARING: Gapless mode prepared." );
8686 } else {
8787 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 );
8989 }
9090
9191 currentPlayer .start (); // Begins playing the music.
@@ -95,7 +95,7 @@ public void onPrepared(MediaPlayer currentPlayer) {
9595 musicEngineListener .onMusicEnginePrepared ();
9696 }
9797
98- Log .d (LOG_TAG , "MUSIC: onPrepared(): Music playback has begun." );
98+ HXLog .d (LOG_TAG , "MUSIC: onPrepared(): Music playback has begun." );
9999 }
100100 });
101101
@@ -120,7 +120,7 @@ public void onCompletion(MediaPlayer mp) {
120120 musicEngineListener .onMusicEngineCompletion ();
121121 }
122122
123- Log .d (LOG_TAG , "MUSIC: onCompletion(): Music playback has completed." );
123+ HXLog .d (LOG_TAG , "MUSIC: onCompletion(): Music playback has completed." );
124124 }
125125 }
126126 });
@@ -133,7 +133,7 @@ public void onCompletion(MediaPlayer mp) {
133133
134134 return true ;
135135 } 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." );
137137 return false ;
138138 }
139139 }
@@ -145,16 +145,16 @@ private MediaPlayer prepareMediaPlayer(Context context) {
145145 // Sets up the MediaPlayer object for the music to be played.
146146 MediaPlayer player = new MediaPlayer (); // Initializes the MediaPlayer.
147147 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." );
149149
150150 // Prepares the specified music URL for playback.
151151 if (musicItem .getMusicUrl () != null ) {
152152 try {
153153 player .setDataSource (context , Uri .parse (musicItem .getMusicUrl ()));
154154 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..." );
156156 } 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 ());
158158 }
159159 }
160160
@@ -164,9 +164,9 @@ else if (musicItem.getMusicResource() != 0) {
164164 AssetFileDescriptor asset = context .getResources ().openRawResourceFd (musicItem .getMusicResource ());
165165 player .setDataSource (asset .getFileDescriptor (), asset .getStartOffset (), asset .getLength ());
166166 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..." );
168168 } 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 ());
170170 }
171171 }
172172
@@ -195,7 +195,7 @@ public void onCompletion(MediaPlayer mp) {
195195 nextPlayer = prepareMediaPlayer (context ); // Prepares the next MediaPlayer.
196196 nextPlayer .setOnPreparedListener (nextPlayerPreparedListener );
197197 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." );
199199 }
200200 };
201201
@@ -210,7 +210,7 @@ public void onBufferingUpdate(MediaPlayer mp, int percent) {
210210 musicEngineListener .onMusicEngineBufferingUpdate (percent );
211211 }
212212
213- Log .d (LOG_TAG , "MUSIC: initMusicEngine(): Music buffering at: " + percent );
213+ HXLog .d (LOG_TAG , "MUSIC: initMusicEngine(): Music buffering at: " + percent );
214214 }
215215 };
216216
@@ -239,12 +239,12 @@ int pauseMusic() {
239239 musicEngineListener .onMusicEnginePause ();
240240 }
241241
242- Log .d (LOG_TAG , "MUSIC: pauseMusic(): Music playback has been paused." );
242+ HXLog .d (LOG_TAG , "MUSIC: pauseMusic(): Music playback has been paused." );
243243 return musicPosition ;
244244 }
245245 }
246246
247- Log .e (LOG_TAG , "ERROR: pauseMusic(): Music could not be paused." );
247+ HXLog .e (LOG_TAG , "ERROR: pauseMusic(): Music could not be paused." );
248248 return 0 ;
249249 }
250250
@@ -256,10 +256,10 @@ boolean release() {
256256 currentPlayer .release ();
257257 currentPlayer = null ;
258258
259- Log .d (LOG_TAG , "RELEASE: release(): MediaPlayer object has been released." );
259+ HXLog .d (LOG_TAG , "RELEASE: release(): MediaPlayer object has been released." );
260260 return true ;
261261 } 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." );
263263 return false ;
264264 }
265265 }
@@ -275,10 +275,10 @@ boolean stopMusic() {
275275 musicEngineListener .onMusicEngineStop ();
276276 }
277277
278- Log .d (LOG_TAG , "MUSIC: stopMusic(): Music playback has been stopped." );
278+ HXLog .d (LOG_TAG , "MUSIC: stopMusic(): Music playback has been stopped." );
279279 return true ;
280280 } 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." );
282282 return false ;
283283 }
284284 }
0 commit comments