1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 02:53:09 +01:00

Addressed review comments

This commit is contained in:
Siddhesh Naik 2024-10-12 21:04:45 +05:30
parent a0ac71c2e1
commit 7509e6482d
7 changed files with 34 additions and 21 deletions

View File

@ -229,6 +229,7 @@ public final class VideoDetailFragment
private ContentObserver settingsContentObserver; private ContentObserver settingsContentObserver;
@Nullable @Nullable
private PlayerService playerService; private PlayerService playerService;
@Nullable
private Player player; private Player player;
private final PlayerHolder playerHolder = PlayerHolder.getInstance(); private final PlayerHolder playerHolder = PlayerHolder.getInstance();
@ -236,7 +237,7 @@ public final class VideoDetailFragment
// Service management // Service management
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
@Override @Override
public void onServiceConnected(final Player connectedPlayer, public void onServiceConnected(@Nullable final Player connectedPlayer,
final PlayerService connectedPlayerService, final PlayerService connectedPlayerService,
final boolean playAfterConnect) { final boolean playAfterConnect) {
player = connectedPlayer; player = connectedPlayer;

View File

@ -163,7 +163,7 @@ public abstract class PlaylistDialog extends DialogFragment implements StateSave
* @return the disposable that was created * @return the disposable that was created
*/ */
public static Disposable showForPlayQueue( public static Disposable showForPlayQueue(
final Player player, @NonNull final Player player,
@NonNull final FragmentManager fragmentManager) { @NonNull final FragmentManager fragmentManager) {
final List<StreamEntity> streamEntities = Stream.of(player.getPlayQueue()) final List<StreamEntity> streamEntities = Stream.of(player.getPlayQueue())

View File

@ -61,6 +61,7 @@ public final class PlayQueueActivity extends AppCompatActivity
private static final int MENU_ID_AUDIO_TRACK = 71; private static final int MENU_ID_AUDIO_TRACK = 71;
@Nullable
private Player player; private Player player;
private boolean serviceBound; private boolean serviceBound;
@ -137,30 +138,38 @@ public final class PlayQueueActivity extends AppCompatActivity
NavigationHelper.openSettings(this); NavigationHelper.openSettings(this);
return true; return true;
case R.id.action_append_playlist: case R.id.action_append_playlist:
if (player != null) {
PlaylistDialog.showForPlayQueue(player, getSupportFragmentManager()); PlaylistDialog.showForPlayQueue(player, getSupportFragmentManager());
}
return true; return true;
case R.id.action_playback_speed: case R.id.action_playback_speed:
openPlaybackParameterDialog(); openPlaybackParameterDialog();
return true; return true;
case R.id.action_mute: case R.id.action_mute:
if (player != null) {
player.toggleMute(); player.toggleMute();
}
return true; return true;
case R.id.action_system_audio: case R.id.action_system_audio:
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS)); startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
return true; return true;
case R.id.action_switch_main: case R.id.action_switch_main:
if (player != null) {
this.player.setRecovery(); this.player.setRecovery();
NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true); NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true);
}
return true; return true;
case R.id.action_switch_popup: case R.id.action_switch_popup:
if (PermissionHelper.isPopupEnabledElseAsk(this)) { if (PermissionHelper.isPopupEnabledElseAsk(this) && player != null) {
this.player.setRecovery(); this.player.setRecovery();
NavigationHelper.playOnPopupPlayer(this, player.getPlayQueue(), true); NavigationHelper.playOnPopupPlayer(this, player.getPlayQueue(), true);
} }
return true; return true;
case R.id.action_switch_background: case R.id.action_switch_background:
if (player != null) {
this.player.setRecovery(); this.player.setRecovery();
NavigationHelper.playOnBackgroundPlayer(this, player.getPlayQueue(), true); NavigationHelper.playOnBackgroundPlayer(this, player.getPlayQueue(), true);
}
return true; return true;
} }
@ -309,7 +318,7 @@ public final class PlayQueueActivity extends AppCompatActivity
@Override @Override
public void onSwiped(final int index) { public void onSwiped(final int index) {
if (index != -1) { if (index != -1 && player != null) {
player.getPlayQueue().remove(index); player.getPlayQueue().remove(index);
} }
} }
@ -659,7 +668,7 @@ public final class PlayQueueActivity extends AppCompatActivity
* @param itemId index of the selected item * @param itemId index of the selected item
*/ */
private void onAudioTrackClick(final int itemId) { private void onAudioTrackClick(final int itemId) {
if (player.getCurrentMetadata() == null) { if (player == null || player.getCurrentMetadata() == null) {
return; return;
} }
player.getCurrentMetadata().getMaybeAudioTrack().ifPresent(audioTrack -> { player.getCurrentMetadata().getMaybeAudioTrack().ifPresent(audioTrack -> {

View File

@ -46,8 +46,7 @@ class PlayerService : MediaBrowserServiceCompat() {
loading stream metadata) takes a lot of time, the app would crash on Android 8+ as the loading stream metadata) takes a lot of time, the app would crash on Android 8+ as the
service would never be put in the foreground while we said to the system we would do so service would never be put in the foreground while we said to the system we would do so
*/ */
UIs() UIs()[NotificationPlayerUi::class.java]
.get(NotificationPlayerUi::class.java)
.ifPresent { it.createNotificationAndStartForeground() } .ifPresent { it.createNotificationAndStartForeground() }
} }
} }
@ -198,10 +197,7 @@ class PlayerService : MediaBrowserServiceCompat() {
) : Binder() { ) : Binder() {
private val playerService = WeakReference(playerService) private val playerService = WeakReference(playerService)
val service: PlayerService? fun getPlayer(): Player? = playerService.get()?.player
get() = playerService.get()
fun getPlayer(): Player = service?.player ?: throw Error("Player service is null")
} }
companion object { companion object {

View File

@ -1,10 +1,12 @@
package org.schabi.newpipe.player.event; package org.schabi.newpipe.player.event;
import androidx.annotation.Nullable;
import org.schabi.newpipe.player.PlayerService; import org.schabi.newpipe.player.PlayerService;
import org.schabi.newpipe.player.Player; import org.schabi.newpipe.player.Player;
public interface PlayerServiceExtendedEventListener extends PlayerServiceEventListener { public interface PlayerServiceExtendedEventListener extends PlayerServiceEventListener {
void onServiceConnected(Player player, void onServiceConnected(@Nullable Player player,
PlayerService playerService, PlayerService playerService,
boolean playAfterConnect); boolean playAfterConnect);
void onServiceDisconnected(); void onServiceDisconnected();

View File

@ -166,7 +166,7 @@ public final class PlayerHolder {
} }
final PlayerService.LocalBinder localBinder = (PlayerService.LocalBinder) service; final PlayerService.LocalBinder localBinder = (PlayerService.LocalBinder) service;
playerService = localBinder.getService(); playerService = localBinder.getPlayer().getService();
player = localBinder.getPlayer(); player = localBinder.getPlayer();
if (listener != null) { if (listener != null) {
listener.onServiceConnected(player, playerService, playAfterConnect); listener.onServiceConnected(player, playerService, playAfterConnect);

View File

@ -59,7 +59,9 @@ import org.schabi.newpipe.util.NavigationHelper
import org.schabi.newpipe.util.ServiceHelper import org.schabi.newpipe.util.ServiceHelper
import java.util.stream.Collectors 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) private val mediaSession = MediaSessionCompat(playerService, TAG)
val sessionConnector = MediaSessionConnector(mediaSession).apply { val sessionConnector = MediaSessionConnector(mediaSession).apply {
setMetadataDeduplicationEnabled(true) setMetadataDeduplicationEnabled(true)
@ -627,7 +629,10 @@ class MediaBrowserConnector(private val playerService: PlayerService) : Playback
private fun handleSearchError(throwable: Throwable) { private fun handleSearchError(throwable: Throwable) {
Log.e(TAG, "Search error: $throwable") Log.e(TAG, "Search error: $throwable")
disposePrepareOrPlayCommands() 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( override fun onPrepareFromUri(