Search in sources :

Example 1 with OnGetGroovesharkStreamKey

use of io.recom.howabout.category.music.net.GroovesharkStreamUrlGetter.OnGetGroovesharkStreamKey in project howabout-android by recomio.

the class MusicPlayerService method play.

@SuppressWarnings("deprecation")
private void play(final String trackTitle, final String artistName, String thumbnailUrl) {
    Notification notification = new Notification(R.drawable.ic_launcher, trackTitle + " - " + artistName, System.currentTimeMillis());
    Intent intent = new Intent(this, MusicPlaylistActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    notification.setLatestEventInfo(this, trackTitle, artistName, pendingIntent);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(NOTIFICATION_ID, notification);
    playlistAdapter.setCurrentLyrics("");
    isLoaded = false;
    isLoading = true;
    mediaPlayer.stop();
    mediaPlayer.reset();
    if (playInfoRequest != null) {
        contentManager.cancel(playInfoRequest);
        playInfoRequest = null;
    }
    playInfoRequest = new PlayInfoRequest(trackTitle, artistName);
    contentManager.execute(playInfoRequest, new RequestListener<PlayInfo>() {

        @Override
        public void onRequestFailure(SpiceException e) {
            if (groovesharkStreamUrlGetter != null) {
                groovesharkStreamUrlGetter.isStopped(true);
            }
            if (e instanceof RequestCancelledException) {
                return;
            }
            isLoading = false;
            playlistAdapter.playNext();
            playlistAdapter.notifyDataSetChanged();
            Toast.makeText(MusicPlayerService.this, trackTitle + "(" + artistName + ")" + "\n 무료 스트리밍 음원을 찾지 못했습니다.", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRequestSuccess(final PlayInfo playInfo) {
            playlistAdapter.setCurrentLyrics(playInfo.getLyrics());
            Log.i("grooveshark", playInfo.getTrackTitle());
            final String groovesharkSongId = playInfo.getTinysongId();
            if (groovesharkSongId != null) {
                HowaboutApplication application = (HowaboutApplication) getApplicationContext();
                try {
                    groovesharkStreamUrlGetter = new GroovesharkStreamUrlGetter(application, groovesharkSongId, new OnGetGroovesharkStreamKey() {

                        @Override
                        public void sucess(String streamUrl) {
                            playInfo.setGroovesharkSongID(groovesharkSongId);
                            playInfo.setGroovesharkStreamUrl(streamUrl);
                            playStream(playInfo);
                        }

                        @Override
                        public void error(Exception e) {
                            playStream(playInfo);
                        }
                    });
                    groovesharkStreamUrlGetter.getGroovesharkStreamUrlAsync();
                } catch (Exception e) {
                    playStream(playInfo);
                }
            } else {
                playStream(playInfo);
            }
        }
    });
}
Also used : GroovesharkStreamUrlGetter(io.recom.howabout.category.music.net.GroovesharkStreamUrlGetter) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) HowaboutApplication(io.recom.howabout.HowaboutApplication) Notification(android.app.Notification) RequestCancelledException(com.octo.android.robospice.exception.RequestCancelledException) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) PlayInfo(io.recom.howabout.category.music.model.PlayInfo) PendingIntent(android.app.PendingIntent) RequestCancelledException(com.octo.android.robospice.exception.RequestCancelledException) OnGetGroovesharkStreamKey(io.recom.howabout.category.music.net.GroovesharkStreamUrlGetter.OnGetGroovesharkStreamKey) PlayInfoRequest(io.recom.howabout.category.music.net.PlayInfoRequest)

Aggregations

Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 RequestCancelledException (com.octo.android.robospice.exception.RequestCancelledException)1 SpiceException (com.octo.android.robospice.persistence.exception.SpiceException)1 HowaboutApplication (io.recom.howabout.HowaboutApplication)1 PlayInfo (io.recom.howabout.category.music.model.PlayInfo)1 GroovesharkStreamUrlGetter (io.recom.howabout.category.music.net.GroovesharkStreamUrlGetter)1 OnGetGroovesharkStreamKey (io.recom.howabout.category.music.net.GroovesharkStreamUrlGetter.OnGetGroovesharkStreamKey)1 PlayInfoRequest (io.recom.howabout.category.music.net.PlayInfoRequest)1