Search in sources :

Example 16 with DownloadService

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

the class VisualizerView method getVizualizer.

private static Visualizer getVizualizer() {
    DownloadService downloadService = DownloadServiceImpl.getInstance();
    VisualizerController visualizerController = downloadService == null ? null : downloadService.getVisualizerController();
    return visualizerController == null ? null : visualizerController.getVisualizer();
}
Also used : VisualizerController(org.moire.ultrasonic.audiofx.VisualizerController) DownloadService(org.moire.ultrasonic.service.DownloadService)

Example 17 with DownloadService

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

the class SearchActivity method onSongSelected.

private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext) {
    DownloadService downloadService = getDownloadService();
    if (downloadService != null) {
        if (!append && !playNext) {
            downloadService.clear();
        }
        downloadService.download(Collections.singletonList(song), save, false, playNext, false, false);
        if (autoplay) {
            downloadService.play(downloadService.size() - 1);
        }
        Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_added, 1, 1));
    }
}
Also used : DownloadService(org.moire.ultrasonic.service.DownloadService)

Example 18 with DownloadService

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

the class DownloadActivity method onCurrentChanged.

private void onCurrentChanged() {
    DownloadService downloadService = getDownloadService();
    if (downloadService == null) {
        return;
    }
    currentPlaying = downloadService.getCurrentPlaying();
    scrollToCurrent();
    long totalDuration = downloadService.getDownloadListDuration();
    long totalSongs = downloadService.getSongs().size();
    int currentSongIndex = downloadService.getCurrentPlayingIndex() + 1;
    String duration = Util.formatTotalDuration(totalDuration);
    String trackFormat = String.format(Locale.getDefault(), "%d / %d", currentSongIndex, totalSongs);
    if (currentPlaying != null) {
        currentSong = currentPlaying.getSong();
        songTitleTextView.setText(currentSong.getTitle());
        albumTextView.setText(currentSong.getAlbum());
        artistTextView.setText(currentSong.getArtist());
        downloadTrackTextView.setText(trackFormat);
        downloadTotalDurationTextView.setText(duration);
        getImageLoader().loadImage(albumArtImageView, currentSong, true, 0, false, true);
    } else {
        currentSong = null;
        songTitleTextView.setText(null);
        albumTextView.setText(null);
        artistTextView.setText(null);
        downloadTrackTextView.setText(null);
        downloadTotalDurationTextView.setText(null);
        getImageLoader().loadImage(albumArtImageView, null, true, 0, false, true);
    }
}
Also used : DownloadService(org.moire.ultrasonic.service.DownloadService) Point(android.graphics.Point)

Example 19 with DownloadService

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

the class DownloadActivity method onCreate.

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.download);
    final WindowManager windowManager = getWindowManager();
    final Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    swipeDistance = (width + height) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
    swipeVelocity = swipeDistance;
    gestureScanner = new GestureDetector(this, this);
    playlistFlipper = (ViewFlipper) findViewById(R.id.download_playlist_flipper);
    emptyTextView = (TextView) findViewById(R.id.download_empty);
    songTitleTextView = (TextView) findViewById(R.id.download_song_title);
    albumTextView = (TextView) findViewById(R.id.download_album);
    artistTextView = (TextView) findViewById(R.id.download_artist);
    albumArtImageView = (ImageView) findViewById(R.id.download_album_art_image);
    positionTextView = (TextView) findViewById(R.id.download_position);
    downloadTrackTextView = (TextView) findViewById(R.id.download_track);
    downloadTotalDurationTextView = (TextView) findViewById(R.id.download_total_duration);
    durationTextView = (TextView) findViewById(R.id.download_duration);
    progressBar = (SeekBar) findViewById(R.id.download_progress_bar);
    playlistView = (DragSortListView) findViewById(R.id.download_list);
    final AutoRepeatButton previousButton = (AutoRepeatButton) findViewById(R.id.download_previous);
    final AutoRepeatButton nextButton = (AutoRepeatButton) findViewById(R.id.download_next);
    pauseButton = findViewById(R.id.download_pause);
    stopButton = findViewById(R.id.download_stop);
    startButton = findViewById(R.id.download_start);
    final View shuffleButton = findViewById(R.id.download_shuffle);
    repeatButton = (ImageView) findViewById(R.id.download_repeat);
    visualizerViewLayout = (LinearLayout) findViewById(R.id.download_visualizer_view_layout);
    View.OnTouchListener touchListener = new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent me) {
            return gestureScanner.onTouchEvent(me);
        }
    };
    albumArtImageView.setOnTouchListener(touchListener);
    albumArtImageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            toggleFullScreenAlbumArt();
        }
    });
    previousButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            warnIfNetworkOrStorageUnavailable();
            new SilentBackgroundTask<Void>(DownloadActivity.this) {

                @Override
                protected Void doInBackground() throws Throwable {
                    getDownloadService().previous();
                    return null;
                }

                @Override
                protected void done(final Void result) {
                    onCurrentChanged();
                    onSliderProgressChanged();
                }
            }.execute();
        }
    });
    previousButton.setOnRepeatListener(new Runnable() {

        @Override
        public void run() {
            int incrementTime = Util.getIncrementTime(DownloadActivity.this);
            changeProgress(-incrementTime);
        }
    });
    nextButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            warnIfNetworkOrStorageUnavailable();
            new SilentBackgroundTask<Boolean>(DownloadActivity.this) {

                @Override
                protected Boolean doInBackground() throws Throwable {
                    if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) {
                        getDownloadService().next();
                        return true;
                    } else {
                        return false;
                    }
                }

                @Override
                protected void done(final Boolean result) {
                    if (result) {
                        onCurrentChanged();
                        onSliderProgressChanged();
                    }
                }
            }.execute();
        }
    });
    nextButton.setOnRepeatListener(new Runnable() {

        @Override
        public void run() {
            int incrementTime = Util.getIncrementTime(DownloadActivity.this);
            changeProgress(incrementTime);
        }
    });
    pauseButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            new SilentBackgroundTask<Void>(DownloadActivity.this) {

                @Override
                protected Void doInBackground() throws Throwable {
                    getDownloadService().pause();
                    return null;
                }

                @Override
                protected void done(final Void result) {
                    onCurrentChanged();
                    onSliderProgressChanged();
                }
            }.execute();
        }
    });
    stopButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            new SilentBackgroundTask<Void>(DownloadActivity.this) {

                @Override
                protected Void doInBackground() throws Throwable {
                    getDownloadService().reset();
                    return null;
                }

                @Override
                protected void done(final Void result) {
                    onCurrentChanged();
                    onSliderProgressChanged();
                }
            }.execute();
        }
    });
    startButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            warnIfNetworkOrStorageUnavailable();
            new SilentBackgroundTask<Void>(DownloadActivity.this) {

                @Override
                protected Void doInBackground() throws Throwable {
                    start();
                    return null;
                }

                @Override
                protected void done(final Void result) {
                    onCurrentChanged();
                    onSliderProgressChanged();
                }
            }.execute();
        }
    });
    shuffleButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            getDownloadService().shuffle();
            Util.toast(DownloadActivity.this, R.string.download_menu_shuffle_notification);
        }
    });
    repeatButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            final RepeatMode repeatMode = getDownloadService().getRepeatMode().next();
            getDownloadService().setRepeatMode(repeatMode);
            onDownloadListChanged();
            switch(repeatMode) {
                case OFF:
                    Util.toast(DownloadActivity.this, R.string.download_repeat_off);
                    break;
                case ALL:
                    Util.toast(DownloadActivity.this, R.string.download_repeat_all);
                    break;
                case SINGLE:
                    Util.toast(DownloadActivity.this, R.string.download_repeat_single);
                    break;
                default:
                    break;
            }
        }
    });
    progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(final SeekBar seekBar) {
            new SilentBackgroundTask<Void>(DownloadActivity.this) {

                @Override
                protected Void doInBackground() throws Throwable {
                    getDownloadService().seekTo(getProgressBar().getProgress());
                    return null;
                }

                @Override
                protected void done(final Void result) {
                    onSliderProgressChanged();
                }
            }.execute();
        }

        @Override
        public void onStartTrackingTouch(final SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
        }
    });
    playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
            warnIfNetworkOrStorageUnavailable();
            new SilentBackgroundTask<Void>(DownloadActivity.this) {

                @Override
                protected Void doInBackground() throws Throwable {
                    getDownloadService().play(position);
                    return null;
                }

                @Override
                protected void done(final Void result) {
                    onCurrentChanged();
                    onSliderProgressChanged();
                }
            }.execute();
        }
    });
    registerForContextMenu(playlistView);
    final DownloadService downloadService = getDownloadService();
    if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) {
        warnIfNetworkOrStorageUnavailable();
        downloadService.setShufflePlayEnabled(true);
    }
    visualizerAvailable = (downloadService != null) && (downloadService.getVisualizerController() != null);
    equalizerAvailable = (downloadService != null) && (downloadService.getEqualizerController() != null);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                DownloadService downloadService = getDownloadService();
                jukeboxAvailable = (downloadService != null) && (downloadService.isJukeboxAvailable());
            } catch (Exception e) {
                Log.e(TAG, e.getMessage(), e);
            }
        }
    }).start();
    final View nowPlayingMenuItem = findViewById(R.id.menu_now_playing);
    menuDrawer.setActiveView(nowPlayingMenuItem);
    if (visualizerAvailable) {
        visualizerView = new VisualizerView(this);
        visualizerViewLayout.addView(visualizerView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
        if (!visualizerView.isActive()) {
            visualizerViewLayout.setVisibility(View.GONE);
        } else {
            visualizerViewLayout.setVisibility(View.VISIBLE);
        }
        visualizerView.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(final View view, final MotionEvent motionEvent) {
                visualizerView.setActive(!visualizerView.isActive());
                getDownloadService().setShowVisualization(visualizerView.isActive());
                return true;
            }
        });
    } else {
        visualizerViewLayout.setVisibility(View.GONE);
    }
}
Also used : SilentBackgroundTask(org.moire.ultrasonic.util.SilentBackgroundTask) GestureDetector(android.view.GestureDetector) DownloadService(org.moire.ultrasonic.service.DownloadService) WindowManager(android.view.WindowManager) AutoRepeatButton(org.moire.ultrasonic.view.AutoRepeatButton) RepeatMode(org.moire.ultrasonic.domain.RepeatMode) VisualizerView(org.moire.ultrasonic.view.VisualizerView) SeekBar(android.widget.SeekBar) Point(android.graphics.Point) ImageView(android.widget.ImageView) VisualizerView(org.moire.ultrasonic.view.VisualizerView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) DragSortListView(com.mobeta.android.dslv.DragSortListView) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout) Display(android.view.Display)

Example 20 with DownloadService

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

the class DownloadActivity method onFling.

@Override
public boolean onFling(final MotionEvent e1, final MotionEvent e2, final float velocityX, final float velocityY) {
    final DownloadService downloadService = getDownloadService();
    if (downloadService == null || e1 == null || e2 == null) {
        return false;
    }
    float e1X = e1.getX();
    float e2X = e2.getX();
    float e1Y = e1.getY();
    float e2Y = e2.getY();
    float absX = Math.abs(velocityX);
    float absY = Math.abs(velocityY);
    // Right to Left swipe
    if (e1X - e2X > swipeDistance && absX > swipeVelocity) {
        warnIfNetworkOrStorageUnavailable();
        if (downloadService.getCurrentPlayingIndex() < downloadService.size() - 1) {
            downloadService.next();
            onCurrentChanged();
            onSliderProgressChanged();
        }
        return true;
    }
    // Left to Right swipe
    if (e2X - e1X > swipeDistance && absX > swipeVelocity) {
        warnIfNetworkOrStorageUnavailable();
        downloadService.previous();
        onCurrentChanged();
        onSliderProgressChanged();
        return true;
    }
    // Top to Bottom swipe
    if (e2Y - e1Y > swipeDistance && absY > swipeVelocity) {
        warnIfNetworkOrStorageUnavailable();
        downloadService.seekTo(downloadService.getPlayerPosition() + 30000);
        onSliderProgressChanged();
        return true;
    }
    // Bottom to Top swipe
    if (e1Y - e2Y > swipeDistance && absY > swipeVelocity) {
        warnIfNetworkOrStorageUnavailable();
        downloadService.seekTo(downloadService.getPlayerPosition() - 8000);
        onSliderProgressChanged();
        return true;
    }
    return false;
}
Also used : 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