package vandy.mooc.utils;

import vandy.mooc.presenter.MusicService;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

/**
 * A ParcelableCommand that's used to play music via an Android
 * Started Service.
 */
public class ParcelableCommandMusicService
       extends ParcelableCommandMusic  {
    /**
     * Debugging tag used by the Android logger.
     */
    private static String TAG = 
        ParcelableCommandMusicService.class.getSimpleName();

    /**
     * A UID generated by Eclipse for serialization purposes.
     */
    private static final long serialVersionUID = 20L;

    /**
     * Store the intent used to launch the MusicService.
     */
    private Intent mIntent;

    /**
     * Constructor.
     */
    public ParcelableCommandMusicService() {
        super();
    }

    /**
     * Start playing the song in the MusicService.
     */
    public void execute(Context context,
                        Bundle args) {
        // Get the SongUri to play.
        final Uri songUri = args.getParcelable(SONG_URI);

        Log.d(TAG,
              "execute() entered with songUri "
              + songUri);

        // Get the Intent for the MusicService.
        mIntent = MusicService.makeIntent(context,
                                          songUri);

        // Start the MusicService via the intent.
        context.startService(mIntent);
    }

    /**
     * Stop playing the song in the MusicService.
     */
    public void unexecute(Context context) {
        // Stop the MusicService via the intent.
        context.stopService(mIntent);
    }
}
