Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62225e87 authored by Rajesh Yengisetty's avatar Rajesh Yengisetty Committed by Gerrit Code Review
Browse files

Merge "Eleven: Remove tracks that give problems from the queue and warn" into cm-12.0

parents 790c64e5 25a2d273
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -166,6 +166,7 @@
    <string name="empty_generic_secondary">To copy music from your computer to your device, use a USB cable.</string>
    <string name="empty_queue_main">No songs in play queue</string>
    <string name="empty_queue_secondary">To add songs to your Play Queue, tap the options menu on a song, album, or artist and select \"Add to queue\".</string>
    <string name="error_playing_track">Unable to play track %1$s, removing it from the queue</string>

    <!-- Section Headers -->
    <string name="header_unknown_year">Unknown year</string>
+40 −5
Original line number Diff line number Diff line
@@ -114,15 +114,20 @@ public class MusicPlaybackService extends Service {
    public static final String PLAYLIST_CHANGED = "com.cyanogenmod.eleven.playlistchanged";

    /**
     * Indicates the repeat mode chaned
     * Indicates the repeat mode changed
     */
    public static final String REPEATMODE_CHANGED = "com.cyanogenmod.eleven.repeatmodechanged";

    /**
     * Indicates the shuffle mode chaned
     * Indicates the shuffle mode changed
     */
    public static final String SHUFFLEMODE_CHANGED = "com.cyanogenmod.eleven.shufflemodechanged";

    /**
     * Indicates the track fails to play
     */
    public static final String TRACK_ERROR = "com.cyanogenmod.eleven.trackerror";

    /**
     * For backwards compatibility reasons, also provide sticky
     * broadcasts under the music package
@@ -324,6 +329,13 @@ public class MusicPlaybackService extends Service {
     */
    public static final int MAX_HISTORY_SIZE = 1000;

    public interface TrackErrorExtra {
        /**
         * Name of the track that was unable to play
         */
        public static final String TRACK_NAME = "trackname";
    }

    /**
     * The columns used to retrieve any info from the current track
     */
@@ -2757,7 +2769,14 @@ public class MusicPlaybackService extends Service {
                        break;
                    case SERVER_DIED:
                        if (service.isPlaying()) {
                            service.gotoNext(true);
                            final Intent i = new Intent(TRACK_ERROR);
                            final TrackErrorInfo info = (TrackErrorInfo)msg.obj;
                            i.putExtra(TrackErrorExtra.TRACK_NAME, info.mTrackName);
                            service.sendBroadcast(i);

                            // since the service isPlaying(), we only need to remove the offending
                            // audio track, and the code will automatically play the next track
                            service.removeTrack(info.mId);
                        } else {
                            service.openCurrentAndNext();
                        }
@@ -2872,6 +2891,16 @@ public class MusicPlaybackService extends Service {
        }
    };

    private static final class TrackErrorInfo {
        public long mId;
        public String mTrackName;

        public TrackErrorInfo(long id, String trackName) {
            mId = id;
            mTrackName = trackName;
        }
    }

    private static final class MultiPlayer implements MediaPlayer.OnErrorListener,
            MediaPlayer.OnCompletionListener {

@@ -3136,13 +3165,19 @@ public class MusicPlaybackService extends Service {
         */
        @Override
        public boolean onError(final MediaPlayer mp, final int what, final int extra) {
            Log.w(TAG, "Music Server Error what: " + what + " extra: " + extra);
            switch (what) {
                case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
                    final MusicPlaybackService service = mService.get();
                    final TrackErrorInfo errorInfo = new TrackErrorInfo(service.getAudioId(),
                            service.getTrackName());

                    mIsInitialized = false;
                    mCurrentMediaPlayer.release();
                    mCurrentMediaPlayer = new MediaPlayer();
                    mCurrentMediaPlayer.setWakeMode(mService.get(), PowerManager.PARTIAL_WAKE_LOCK);
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(SERVER_DIED), 2000);
                    mCurrentMediaPlayer.setWakeMode(service, PowerManager.PARTIAL_WAKE_LOCK);
                    Message msg = mHandler.obtainMessage(SERVER_DIED, errorInfo);
                    mHandler.sendMessageDelayed(msg, 2000);
                    return true;
                default:
                    break;
+7 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.cyanogenmod.eleven.R;
import com.cyanogenmod.eleven.cache.ICacheListener;
import com.cyanogenmod.eleven.cache.ImageFetcher;
import com.cyanogenmod.eleven.utils.ApolloUtils;
import com.cyanogenmod.eleven.utils.CustomToast;
import com.cyanogenmod.eleven.utils.Lists;
import com.cyanogenmod.eleven.utils.MusicUtils;
import com.cyanogenmod.eleven.utils.MusicUtils.ServiceToken;
@@ -226,6 +227,8 @@ public abstract class BaseActivity extends FragmentActivity implements ServiceCo
        filter.addAction(MusicPlaybackService.REFRESH);
        // If a playlist has changed, notify us
        filter.addAction(MusicPlaybackService.PLAYLIST_CHANGED);
        // If there is an error playing a track
        filter.addAction(MusicPlaybackService.TRACK_ERROR);
        registerReceiver(mPlaybackStatus, filter);

        mPlayPauseProgressButton.resume();
@@ -391,6 +394,10 @@ public abstract class BaseActivity extends FragmentActivity implements ServiceCo
                    baseActivity.restartLoader();
                } else if (action.equals(MusicPlaybackService.PLAYLIST_CHANGED)) {
                    baseActivity.onPlaylistChanged();
                } else if (action.equals(MusicPlaybackService.TRACK_ERROR)) {
                    final String errorMsg = context.getString(R.string.error_playing_track,
                            intent.getStringExtra(MusicPlaybackService.TrackErrorExtra.TRACK_NAME));
                    CustomToast.makeText(baseActivity, errorMsg, CustomToast.LENGTH_SHORT).show();
                }
            }
        }