Search in sources :

Example 1 with ExternalMedia

use of de.danoeh.antennapod.core.util.playback.ExternalMedia in project AntennaPod by AntennaPod.

the class PlaybackService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    Log.d(TAG, "OnStartCommand called");
    final int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
    final boolean castDisconnect = intent.getBooleanExtra(EXTRA_CAST_DISCONNECT, false);
    final Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
    if (keycode == -1 && playable == null && !castDisconnect) {
        Log.e(TAG, "PlaybackService was started with no arguments");
        stopSelf();
        return Service.START_REDELIVER_INTENT;
    }
    if ((flags & Service.START_FLAG_REDELIVERY) != 0) {
        Log.d(TAG, "onStartCommand is a redelivered intent, calling stopForeground now.");
        stopForeground(true);
    } else {
        if (keycode != -1) {
            Log.d(TAG, "Received media button event");
            handleKeycode(keycode, intent.getIntExtra(MediaButtonReceiver.EXTRA_SOURCE, InputDeviceCompat.SOURCE_CLASS_NONE));
        } else if (!flavorHelper.castDisconnect(castDisconnect)) {
            started = true;
            boolean stream = intent.getBooleanExtra(EXTRA_SHOULD_STREAM, true);
            boolean startWhenPrepared = intent.getBooleanExtra(EXTRA_START_WHEN_PREPARED, false);
            boolean prepareImmediately = intent.getBooleanExtra(EXTRA_PREPARE_IMMEDIATELY, false);
            sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
            //If the user asks to play External Media, the casting session, if on, should end.
            flavorHelper.castDisconnect(playable instanceof ExternalMedia);
            mediaPlayer.playMediaObject(playable, stream, startWhenPrepared, prepareImmediately);
        }
    }
    return Service.START_REDELIVER_INTENT;
}
Also used : Playable(de.danoeh.antennapod.core.util.playback.Playable) ExternalMedia(de.danoeh.antennapod.core.util.playback.ExternalMedia)

Example 2 with ExternalMedia

use of de.danoeh.antennapod.core.util.playback.ExternalMedia in project AntennaPod by AntennaPod.

the class AudioplayerActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    if (TextUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) {
        Intent intent = getIntent();
        Log.d(TAG, "Received VIEW intent: " + intent.getData().getPath());
        ExternalMedia media = new ExternalMedia(intent.getData().getPath(), MediaType.AUDIO);
        Intent launchIntent = new Intent(this, PlaybackService.class);
        launchIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
        launchIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, true);
        launchIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM, false);
        launchIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY, true);
        startService(launchIntent);
    } else if (PlaybackService.isCasting()) {
        Intent intent = PlaybackService.getPlayerActivityIntent(this);
        if (!intent.getComponent().getClassName().equals(AudioplayerActivity.class.getName())) {
            saveCurrentFragment();
            finish();
            startActivity(intent);
        }
    }
}
Also used : ExternalMedia(de.danoeh.antennapod.core.util.playback.ExternalMedia) Intent(android.content.Intent)

Example 3 with ExternalMedia

use of de.danoeh.antennapod.core.util.playback.ExternalMedia in project AntennaPod by AntennaPod.

the class ExternalMediaTest method testSaveCurrentPositionUpdatesPreferences.

public void testSaveCurrentPositionUpdatesPreferences() {
    final int POSITION = 50;
    final int LAST_PLAYED_TIME = 1650;
    assertEquals(NOT_SET, getDefaultSharedPrefs().getInt(ExternalMedia.PREF_POSITION, NOT_SET));
    assertEquals(NOT_SET, getDefaultSharedPrefs().getLong(ExternalMedia.PREF_LAST_PLAYED_TIME, NOT_SET));
    ExternalMedia media = new ExternalMedia("source", MediaType.AUDIO);
    media.saveCurrentPosition(getDefaultSharedPrefs(), POSITION, LAST_PLAYED_TIME);
    assertEquals(POSITION, getDefaultSharedPrefs().getInt(ExternalMedia.PREF_POSITION, NOT_SET));
    assertEquals(LAST_PLAYED_TIME, getDefaultSharedPrefs().getLong(ExternalMedia.PREF_LAST_PLAYED_TIME, NOT_SET));
}
Also used : ExternalMedia(de.danoeh.antennapod.core.util.playback.ExternalMedia) SuppressLint(android.annotation.SuppressLint)

Example 4 with ExternalMedia

use of de.danoeh.antennapod.core.util.playback.ExternalMedia in project AntennaPod by AntennaPod.

the class VideoplayerActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_VIEW)) {
        Intent intent = getIntent();
        Log.d(TAG, "Received VIEW intent: " + intent.getData().getPath());
        ExternalMedia media = new ExternalMedia(intent.getData().getPath(), MediaType.VIDEO);
        Intent launchIntent = new Intent(this, PlaybackService.class);
        launchIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
        launchIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, true);
        launchIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM, false);
        launchIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY, true);
        startService(launchIntent);
    } else if (PlaybackService.isCasting()) {
        Intent intent = PlaybackService.getPlayerActivityIntent(this);
        if (!intent.getComponent().getClassName().equals(VideoplayerActivity.class.getName())) {
            destroyingDueToReload = true;
            finish();
            startActivity(intent);
        }
    }
}
Also used : ExternalMedia(de.danoeh.antennapod.core.util.playback.ExternalMedia) Intent(android.content.Intent)

Aggregations

ExternalMedia (de.danoeh.antennapod.core.util.playback.ExternalMedia)4 Intent (android.content.Intent)2 SuppressLint (android.annotation.SuppressLint)1 Playable (de.danoeh.antennapod.core.util.playback.Playable)1