Search in sources :

Example 21 with DownloadService

use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.

the class A2dpIntentReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    DownloadService downloadService = DownloadServiceImpl.getInstance();
    if (downloadService == null) {
        return;
    }
    if (downloadService.getCurrentPlaying() == null) {
        return;
    }
    Entry song = downloadService.getCurrentPlaying().getSong();
    if (song == null) {
        return;
    }
    Intent avrcpIntent = new Intent(PLAYSTATUS_RESPONSE);
    Integer duration = song.getDuration();
    Integer playerPosition = downloadService.getPlayerPosition();
    Integer listSize = downloadService.getDownloads().size();
    if (duration != null) {
        avrcpIntent.putExtra("duration", (long) duration);
    }
    avrcpIntent.putExtra("position", (long) playerPosition);
    avrcpIntent.putExtra("ListSize", (long) listSize);
    switch(downloadService.getPlayerState()) {
        case STARTED:
            avrcpIntent.putExtra("playing", true);
            break;
        case STOPPED:
            avrcpIntent.putExtra("playing", false);
            break;
        case PAUSED:
            avrcpIntent.putExtra("playing", false);
            break;
        case COMPLETED:
            avrcpIntent.putExtra("playing", false);
            break;
        default:
            return;
    }
    context.sendBroadcast(avrcpIntent);
}
Also used : Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) Intent(android.content.Intent) DownloadService(org.moire.ultrasonic.service.DownloadService)

Aggregations

DownloadService (org.moire.ultrasonic.service.DownloadService)21 Point (android.graphics.Point)6 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)4 DownloadFile (org.moire.ultrasonic.service.DownloadFile)4 Intent (android.content.Intent)3 PlayerState (org.moire.ultrasonic.domain.PlayerState)3 View (android.view.View)2 TextView (android.widget.TextView)2 DragSortListView (com.mobeta.android.dslv.DragSortListView)2 ArrayList (java.util.ArrayList)2 MusicService (org.moire.ultrasonic.service.MusicService)2 SilentBackgroundTask (org.moire.ultrasonic.util.SilentBackgroundTask)2 SharedPreferences (android.content.SharedPreferences)1 Paint (android.graphics.Paint)1 Drawable (android.graphics.drawable.Drawable)1 AudioManager (android.media.AudioManager)1 OnAudioFocusChangeListener (android.media.AudioManager.OnAudioFocusChangeListener)1 Handler (android.os.Handler)1 Display (android.view.Display)1 GestureDetector (android.view.GestureDetector)1