Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
snaik20 committed Oct 12, 2024
1 parent c91c9f9 commit 9b695a8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ public final class VideoDetailFragment
private ContentObserver settingsContentObserver;
@Nullable
private PlayerService playerService;
@Nullable
private Player player;
private final PlayerHolder playerHolder = PlayerHolder.getInstance();

/*//////////////////////////////////////////////////////////////////////////
// Service management
//////////////////////////////////////////////////////////////////////////*/
@Override
public void onServiceConnected(final Player connectedPlayer,
public void onServiceConnected(@Nullable final Player connectedPlayer,
final PlayerService connectedPlayerService,
final boolean playAfterConnect) {
player = connectedPlayer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static Disposable createCorrespondingDialog(
* @return the disposable that was created
*/
public static Disposable showForPlayQueue(
final Player player,
@NonNull final Player player,
@NonNull final FragmentManager fragmentManager) {

final List<StreamEntity> streamEntities = Stream.of(player.getPlayQueue())
Expand Down
27 changes: 18 additions & 9 deletions app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public final class PlayQueueActivity extends AppCompatActivity

private static final int MENU_ID_AUDIO_TRACK = 71;

@Nullable
private Player player;

private boolean serviceBound;
Expand Down Expand Up @@ -137,30 +138,38 @@ public boolean onOptionsItemSelected(final MenuItem item) {
NavigationHelper.openSettings(this);
return true;
case R.id.action_append_playlist:
PlaylistDialog.showForPlayQueue(player, getSupportFragmentManager());
if (player != null) {
PlaylistDialog.showForPlayQueue(player, getSupportFragmentManager());
}
return true;
case R.id.action_playback_speed:
openPlaybackParameterDialog();
return true;
case R.id.action_mute:
player.toggleMute();
if (player != null) {
player.toggleMute();
}
return true;
case R.id.action_system_audio:
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
return true;
case R.id.action_switch_main:
this.player.setRecovery();
NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true);
if (player != null) {
this.player.setRecovery();
NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true);
}
return true;
case R.id.action_switch_popup:
if (PermissionHelper.isPopupEnabledElseAsk(this)) {
if (PermissionHelper.isPopupEnabledElseAsk(this) && player != null) {
this.player.setRecovery();
NavigationHelper.playOnPopupPlayer(this, player.getPlayQueue(), true);
}
return true;
case R.id.action_switch_background:
this.player.setRecovery();
NavigationHelper.playOnBackgroundPlayer(this, player.getPlayQueue(), true);
if (player != null) {
this.player.setRecovery();
NavigationHelper.playOnBackgroundPlayer(this, player.getPlayQueue(), true);
}
return true;
}

Expand Down Expand Up @@ -309,7 +318,7 @@ public void onMove(final int sourceIndex, final int targetIndex) {

@Override
public void onSwiped(final int index) {
if (index != -1) {
if (index != -1 && player != null) {
player.getPlayQueue().remove(index);
}
}
Expand Down Expand Up @@ -659,7 +668,7 @@ private void buildAudioTrackMenu() {
* @param itemId index of the selected item
*/
private void onAudioTrackClick(final int itemId) {
if (player.getCurrentMetadata() == null) {
if (player == null || player.getCurrentMetadata() == null) {
return;
}
player.getCurrentMetadata().getMaybeAudioTrack().ifPresent(audioTrack -> {
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/org/schabi/newpipe/player/PlayerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ class PlayerService : MediaBrowserServiceCompat() {
) : Binder() {
private val playerService = WeakReference(playerService)

val service: PlayerService?
get() = playerService.get()

fun getPlayer(): Player = service?.player ?: throw Error("Player service is null")
fun getPlayer(): Player? = playerService.get()?.player
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.schabi.newpipe.player.event;

import androidx.annotation.Nullable;

import org.schabi.newpipe.player.PlayerService;
import org.schabi.newpipe.player.Player;

public interface PlayerServiceExtendedEventListener extends PlayerServiceEventListener {
void onServiceConnected(Player player,
void onServiceConnected(@Nullable Player player,
PlayerService playerService,
boolean playAfterConnect);
void onServiceDisconnected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void onServiceConnected(final ComponentName compName, final IBinder servi
}
final PlayerService.LocalBinder localBinder = (PlayerService.LocalBinder) service;

playerService = localBinder.getService();
playerService = localBinder.getPlayer().getService();
player = localBinder.getPlayer();
if (listener != null) {
listener.onServiceConnected(player, playerService, playAfterConnect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ import org.schabi.newpipe.util.NavigationHelper
import org.schabi.newpipe.util.ServiceHelper
import java.util.stream.Collectors

class MediaBrowserConnector(private val playerService: PlayerService) : PlaybackPreparer {
class MediaBrowserConnector(
private val playerService: PlayerService,
) : PlaybackPreparer {
private val mediaSession = MediaSessionCompat(playerService, TAG)
val sessionConnector = MediaSessionConnector(mediaSession).apply {
setMetadataDeduplicationEnabled(true)
Expand Down Expand Up @@ -627,7 +629,10 @@ class MediaBrowserConnector(private val playerService: PlayerService) : Playback
private fun handleSearchError(throwable: Throwable) {
Log.e(TAG, "Search error: $throwable")
disposePrepareOrPlayCommands()
playbackError(R.string.content_not_supported, PlaybackStateCompat.ERROR_CODE_NOT_SUPPORTED)
sessionConnector.setCustomErrorMessage(
playerService.getString(R.string.search_no_results),
PlaybackStateCompat.ERROR_CODE_APP_ERROR,
)
}

override fun onPrepareFromUri(
Expand Down

0 comments on commit 9b695a8

Please sign in to comment.