More bug fixes
This commit is contained in:
parent
94763814c5
commit
aefd490278
5 changed files with 34 additions and 37 deletions
|
|
@ -283,8 +283,8 @@ public class MusicService extends Service implements MediaPlayer.OnPreparedListe
|
||||||
registerEverything();
|
registerEverything();
|
||||||
isPlayerPrepared = false;
|
isPlayerPrepared = false;
|
||||||
player.reset();
|
player.reset();
|
||||||
Uri trackUri = getCurrentPositionTrackUri();
|
|
||||||
try {
|
try {
|
||||||
|
Uri trackUri = getCurrentPositionTrackUri();
|
||||||
player.setDataSource(getApplicationContext(), trackUri);
|
player.setDataSource(getApplicationContext(), trackUri);
|
||||||
currentSongId = getPlayingQueue().get(getPosition()).id;
|
currentSongId = getPlayingQueue().get(getPosition()).id;
|
||||||
updateNotification();
|
updateNotification();
|
||||||
|
|
@ -298,8 +298,6 @@ public class MusicService extends Service implements MediaPlayer.OnPreparedListe
|
||||||
playingNotificationHelper.updatePlayState(false);
|
playingNotificationHelper.updatePlayState(false);
|
||||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
|
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Toast.makeText(this, getResources().getString(R.string.audio_focus_denied), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
notifyOnMusicRemoteEventListeners(MusicRemoteEvent.TRACK_CHANGED);
|
notifyOnMusicRemoteEventListeners(MusicRemoteEvent.TRACK_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,7 @@ public class MusicControllerActivity extends AbsFabActivity implements OnMusicRe
|
||||||
if (getApp().getMusicPlayerRemote().getPosition() >= 0) {
|
if (getApp().getMusicPlayerRemote().getPosition() >= 0) {
|
||||||
song = getApp().getMusicPlayerRemote().getPlayingQueue().get(getApp().getMusicPlayerRemote().getPosition());
|
song = getApp().getMusicPlayerRemote().getPlayingQueue().get(getApp().getMusicPlayerRemote().getPosition());
|
||||||
} else {
|
} else {
|
||||||
|
song = new Song();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.materialmusic.ui.activities.base;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.GestureDetector;
|
import android.view.GestureDetector;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -78,6 +79,10 @@ public abstract class AbsFabActivity extends AbsBaseActivity implements OnMusicR
|
||||||
protected FloatingActionButton getFab() {
|
protected FloatingActionButton getFab() {
|
||||||
if (fab == null) {
|
if (fab == null) {
|
||||||
fab = (FloatingActionButton) findViewById(R.id.fab);
|
fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
|
if(fab == null){
|
||||||
|
fab = new FloatingActionButton(this);
|
||||||
|
Log.e(getTag(), "No FAB found created default FAB.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return fab;
|
return fab;
|
||||||
}
|
}
|
||||||
|
|
@ -92,13 +97,13 @@ public abstract class AbsFabActivity extends AbsBaseActivity implements OnMusicR
|
||||||
@Override
|
@Override
|
||||||
public void enableViews() {
|
public void enableViews() {
|
||||||
super.enableViews();
|
super.enableViews();
|
||||||
fab.setEnabled(true);
|
getFab().setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disableViews() {
|
public void disableViews() {
|
||||||
super.disableViews();
|
super.disableViews();
|
||||||
fab.setEnabled(false);
|
getFab().setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -144,19 +149,19 @@ public abstract class AbsFabActivity extends AbsBaseActivity implements OnMusicR
|
||||||
public void onMusicRemoteEvent(MusicRemoteEvent event) {
|
public void onMusicRemoteEvent(MusicRemoteEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case MusicRemoteEvent.PLAY:
|
case MusicRemoteEvent.PLAY:
|
||||||
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_pause_white_48dp));
|
getFab().setImageDrawable(getResources().getDrawable(R.drawable.ic_pause_white_48dp));
|
||||||
break;
|
break;
|
||||||
case MusicRemoteEvent.PAUSE:
|
case MusicRemoteEvent.PAUSE:
|
||||||
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_play_arrow_white_48dp));
|
getFab().setImageDrawable(getResources().getDrawable(R.drawable.ic_play_arrow_white_48dp));
|
||||||
break;
|
break;
|
||||||
case MusicRemoteEvent.RESUME:
|
case MusicRemoteEvent.RESUME:
|
||||||
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_pause_white_48dp));
|
getFab().setImageDrawable(getResources().getDrawable(R.drawable.ic_pause_white_48dp));
|
||||||
break;
|
break;
|
||||||
case MusicRemoteEvent.STOP:
|
case MusicRemoteEvent.STOP:
|
||||||
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_play_arrow_white_48dp));
|
getFab().setImageDrawable(getResources().getDrawable(R.drawable.ic_play_arrow_white_48dp));
|
||||||
break;
|
break;
|
||||||
case MusicRemoteEvent.QUEUE_COMPLETED:
|
case MusicRemoteEvent.QUEUE_COMPLETED:
|
||||||
fab.setImageResource(R.drawable.ic_play_arrow_white_48dp);
|
getFab().setImageResource(R.drawable.ic_play_arrow_white_48dp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -430,7 +430,7 @@ public abstract class AbsTagEditorActivity extends ActionBarActivity {
|
||||||
try {
|
try {
|
||||||
return AudioFileIO.read(new File(path));
|
return AudioFileIO.read(new File(path));
|
||||||
} catch (CannotReadException | ReadOnlyFileException | InvalidAudioFrameException | TagException | IOException e) {
|
} catch (CannotReadException | ReadOnlyFileException | InvalidAudioFrameException | TagException | IOException e) {
|
||||||
Log.e(TAG, "error while trying to create the AudioFile from File", e);
|
Log.e(TAG, "Error while trying to create the AudioFile from java.io.File", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -438,49 +438,43 @@ public abstract class AbsTagEditorActivity extends ActionBarActivity {
|
||||||
protected String getAlbumTitle() {
|
protected String getAlbumTitle() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException ignored) {}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getArtistName() {
|
protected String getArtistName() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ARTIST);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ARTIST);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException ignored) {}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getAlbumArtistName() {
|
protected String getAlbumArtistName() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM_ARTIST);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM_ARTIST);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException ignored) {}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getGenreName() {
|
protected String getGenreName() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.GENRE);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.GENRE);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException ignored) {}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getSongYear() {
|
protected String getSongYear() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.YEAR);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.YEAR);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException ignored) {}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getTrackNumber() {
|
protected String getTrackNumber() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TRACK);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TRACK);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException ignored) {}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Bitmap getAlbumArt() {
|
protected Bitmap getAlbumArt() {
|
||||||
|
|
@ -490,8 +484,7 @@ public abstract class AbsTagEditorActivity extends ActionBarActivity {
|
||||||
byte[] artworkBinaryData = artworkTag.getBinaryData();
|
byte[] artworkBinaryData = artworkTag.getBinaryData();
|
||||||
return BitmapFactory.decodeByteArray(artworkBinaryData, 0, artworkBinaryData.length);
|
return BitmapFactory.decodeByteArray(artworkBinaryData, 0, artworkBinaryData.length);
|
||||||
}
|
}
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException ignored) {}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,12 +48,12 @@ public class ImageLoaderUtil {
|
||||||
public static class defaultAlbumArtOnFailed implements ImageLoadingListener {
|
public static class defaultAlbumArtOnFailed implements ImageLoadingListener {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingStarted(String imageUri, View view) {
|
public void onLoadingStarted(String imageUri, View view) {
|
||||||
((ImageView) view).setImageResource(R.drawable.default_album_art);
|
if (view != null) ((ImageView) view).setImageResource(R.drawable.default_album_art);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||||
((ImageView) view).setImageResource(R.drawable.default_album_art);
|
if (view != null) ((ImageView) view).setImageResource(R.drawable.default_album_art);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -63,7 +63,7 @@ public class ImageLoaderUtil {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingCancelled(String imageUri, View view) {
|
public void onLoadingCancelled(String imageUri, View view) {
|
||||||
((ImageView) view).setImageResource(R.drawable.default_album_art);
|
if (view != null) ((ImageView) view).setImageResource(R.drawable.default_album_art);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,12 +71,12 @@ public class ImageLoaderUtil {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingStarted(String imageUri, View view) {
|
public void onLoadingStarted(String imageUri, View view) {
|
||||||
((ImageView) view).setImageResource(R.drawable.default_artist_image);
|
if (view != null) ((ImageView) view).setImageResource(R.drawable.default_artist_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||||
((ImageView) view).setImageResource(R.drawable.default_artist_image);
|
if (view != null) ((ImageView) view).setImageResource(R.drawable.default_artist_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -86,7 +86,7 @@ public class ImageLoaderUtil {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingCancelled(String imageUri, View view) {
|
public void onLoadingCancelled(String imageUri, View view) {
|
||||||
((ImageView) view).setImageResource(R.drawable.default_artist_image);
|
if (view != null) ((ImageView) view).setImageResource(R.drawable.default_artist_image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue