Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/main/assets/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ <h3>Live chat controls</h3>
<li>Use compact Material 3 recording and menu actions with space between controls and the screen edges. Show Retry only after a connection failure, and keep Saved chat and danmaku available from the menu.</li>
<li>Keep the newest messages visible above the bottom navigation while the video header is expanded.</li>
</ul>
<h3>Channel playback mute</h3>
<ul>
<li>Add a mute button beside fullscreen in the main and popup video controls, available without opening the extra tools.</li>
<li>Remember mute and unmute for each service and channel across videos and app restarts. Videos without a channel keep a temporary choice for that video.</li>
</ul>
</div>
</section>
<section id="release-1053000" data-version="1.53.0" data-version-code="1053000">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* SPDX-FileCopyrightText: 2026 WizeStream contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package org.schabi.newpipe.player

import android.content.Context
import org.schabi.newpipe.extractor.stream.StreamInfo
import org.schabi.newpipe.player.helper.ChannelPlaybackMutePreferences
import org.schabi.newpipe.player.playqueue.PlayQueueItem

/** Resolves channel identity before applying sound, while preserving an explicit in-session choice. */
internal class ChannelPlaybackMuteController(
context: Context,
private val onChanged: () -> Unit
) {
private val preferences = ChannelPlaybackMutePreferences(context)
private var stream: Pair<Int, String>? = null
private var channelKey: String? = null
private var explicitChoice: Boolean? = null

var isMuted: Boolean = false
private set

val hasChannelIdentity: Boolean get() = channelKey != null

fun begin(item: PlayQueueItem?) {
if (item == null) return
select(item.serviceId, item.url, item.uploaderUrl.takeUnless { item.isLocalMedia })
}

fun select(serviceId: Int, url: String, uploaderUrl: String?) {
val identity = serviceId to url
if (stream != identity) {
stream = identity
explicitChoice = null
channelKey = preferences.key(serviceId, uploaderUrl)
isMuted = channelKey?.let(preferences::isMuted) ?: false
onChanged()
} else {
resolveChannel(serviceId, uploaderUrl)
}
}

fun onMetadata(info: StreamInfo) {
// Extraction for the previous video may finish after the next one is selected.
if (stream != (info.serviceId to info.url)) return
resolveChannel(info.serviceId, info.uploaderUrl)
}

fun toggle() {
isMuted = !isMuted
explicitChoice = isMuted
channelKey?.let { preferences.save(it, isMuted) }
onChanged()
}

private fun resolveChannel(serviceId: Int, uploaderUrl: String?) {
val key = preferences.key(serviceId, uploaderUrl) ?: return
if (key == channelKey) return
channelKey = key
val explicit = explicitChoice
if (explicit != null) {
// A click made before the uploader was known belongs to this video, not stale metadata.
preferences.save(key, explicit)
} else {
isMuted = preferences.isMuted(key)
}
onChanged()
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/org/schabi/newpipe/player/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Bitmap
import android.view.LayoutInflater
import androidx.media3.common.MediaItem
import androidx.media3.common.PlaybackException
import androidx.media3.common.PlaybackParameters
import androidx.media3.common.Player as Media3Player
Expand Down Expand Up @@ -347,11 +348,15 @@ class Player(

fun setPlayQueueForLifecycle(queue: PlayQueue) {
activePlayQueue = queue
// The previous engine has been released, and the new queue has not been prepared yet.
audioController.beginItem(queue.item)
queueRecovery.bind(queue)
}

fun setExoPlayerForLifecycle(exoPlayer: ExoPlayer) {
media3Player = exoPlayer
// A new engine starts at full volume; restore the selected channel before preparing media.
applyPlayerVolume()
}

fun clearExoPlayerForLifecycle() {
Expand Down Expand Up @@ -485,6 +490,11 @@ class Player(
val isMuted: Boolean
get() = audioController.isMuted

val hasChannelMuteIdentity: Boolean
get() = audioController.hasChannelMuteIdentity

fun onChannelPlaybackMetadata(info: StreamInfo) = audioController.onMetadata(info)

val equalizerState: EqualizerState
get() = audioController.equalizerState

Expand Down Expand Up @@ -578,6 +588,10 @@ class Player(

override fun onMetadata(metadata: androidx.media3.common.Metadata) = historyController.onRadioMetadata(metadata)

override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
audioController.onMediaItemTransition(mediaItem)
}

override fun onEvents(player: Media3Player, events: Media3Player.Events) {
media3ListenerController.onEvents(player)
historyController.onPlaybackEvents()
Expand Down Expand Up @@ -880,6 +894,7 @@ class Player(

fun setCurrentItemForPlaybackSynchronization(item: PlayQueueItem) {
activeItem = item
audioController.beginItem(item)
}

fun clearCurrentPlaybackForBlock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@

package org.schabi.newpipe.player

import androidx.media3.common.MediaItem
import org.schabi.newpipe.extractor.stream.StreamInfo
import org.schabi.newpipe.player.boost.VolumeBoostController
import org.schabi.newpipe.player.equalizer.EqualizerController
import org.schabi.newpipe.player.equalizer.EqualizerState
import org.schabi.newpipe.player.mediaitem.LocalMediaItemTag
import org.schabi.newpipe.player.mediaitem.MediaItemTag
import org.schabi.newpipe.player.mediaitem.PlaceholderTag
import org.schabi.newpipe.player.mediasource.LoadedMediaSource
import org.schabi.newpipe.player.playqueue.PlayQueueItem

/** Owns mute, real-time audio effects, audio focus, and effective-volume coordination. */
internal class PlayerAudioController(private val player: Player) {
Expand All @@ -19,8 +26,27 @@ internal class PlayerAudioController(private val player: Player) {
player::updateAudioTunneling
)

var isMuted = false
private set
private val channelMute = ChannelPlaybackMuteController(player.context, ::applyMute)

val isMuted: Boolean get() = channelMute.isMuted
val hasChannelMuteIdentity: Boolean get() = channelMute.hasChannelIdentity

fun beginItem(item: PlayQueueItem?) = channelMute.begin(item)

fun onMetadata(info: StreamInfo) = channelMute.onMetadata(info)

fun onMediaItemTransition(item: MediaItem?) {
val engine = player.getExoPlayer() ?: return
if (item != engine.currentMediaItem) return
MediaItemTag.from(item).ifPresent { tag ->
if (tag is PlaceholderTag) return@ifPresent
// Extractors may canonicalize the URL. Keep clicks made while the original item loaded.
val source = tag.getMaybeExtras(Any::class.java).orElse(null) as? LoadedMediaSource
val queueItem = source?.stream
val uploaderUrl = if (tag is LocalMediaItemTag) null else tag.uploaderUrl
channelMute.select(tag.serviceId, queueItem?.url ?: tag.streamUrl, uploaderUrl)
}
}

val equalizerState: EqualizerState
get() = equalizer.state
Expand Down Expand Up @@ -68,16 +94,20 @@ internal class PlayerAudioController(private val player: Player) {
}

fun toggleMute() {
val audioReactor = player.audioReactor
if (player.exoPlayerIsNull() || audioReactor == null) {
if (player.exoPlayerIsNull() || player.audioReactor == null) {
return
}
isMuted = !isMuted
// Media3 may have switched items before the batched metadata/UI callback is delivered.
onMediaItemTransition(player.exoPlayer.currentMediaItem)
channelMute.toggle()
}

private fun applyMute() {
player.applyPlayerVolume()
if (isMuted) {
audioReactor.abandonAudioFocus()
} else {
audioReactor.requestAudioFocus()
player.audioReactor?.abandonAudioFocus()
} else if (player.playWhenReady) {
player.audioReactor?.requestAudioFocus()
}
player.UIs().call { ui -> ui.onMuteUnmuteChanged(isMuted) }
player.notifyPlaybackUpdateToListeners()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ internal class PlayerMedia3ListenerController(
}

fun onEvents(media3Player: Media3Player) {
if (player.getExoPlayer() === media3Player) {
audioController.onMediaItemTransition(media3Player.currentMediaItem)
}
metadataController.onEvents(media3Player)
playbackParametersController.updateLiveCatchup()
// A seamless item transition can reuse the decoder without another size or first-frame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ internal class PlayerMetadataController(
}

tag.maybeStreamInfo.ifPresent { info ->
player.onChannelPlaybackMetadata(info)
if (Player.DEBUG) {
android.util.Log.d(
Player.TAG,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* SPDX-FileCopyrightText: 2026 WizeStream contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package org.schabi.newpipe.player.helper

import android.content.Context
import androidx.preference.PreferenceManager

/** Explicit channel mute choices share the existing app-wide service/uploader identity. */
internal class ChannelPlaybackMutePreferences(context: Context) {
private val preferences = PreferenceManager.getDefaultSharedPreferences(context)

fun key(serviceId: Int, uploaderUrl: String?): String? = if (serviceId < 0) {
null
} else {
ChannelPlaybackProfileManager.profileKey(serviceId, uploaderUrl)?.plus(".muted")
}

fun isMuted(key: String): Boolean = try {
preferences.getBoolean(key, false)
} catch (_: ClassCastException) {
false
}

fun save(key: String, muted: Boolean) {
preferences.edit().apply {
if (muted) putBoolean(key, true) else remove(key)
}.apply()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* SPDX-FileCopyrightText: 2026 WizeStream contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package org.schabi.newpipe.player.ui

import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.appcompat.content.res.AppCompatResources
import org.schabi.newpipe.R
import org.schabi.newpipe.databinding.PlayerBinding

/** Sound and fullscreen remain beside one another without opening the optional tools row. */
object ChannelMuteControls {
@JvmStatic
fun bind(binding: PlayerBinding, mute: View.OnClickListener?, fullscreen: View.OnClickListener?) {
binding.channelMuteButton.setOnClickListener(mute)
binding.popupMuteButton.setOnClickListener(mute)
binding.popupFullscreenButton.setOnClickListener(fullscreen)
if (mute == null) restorePopupTools(binding)
}

@JvmStatic
fun show(binding: PlayerBinding, popup: Boolean) {
binding.channelMuteButton.visibility = if (popup) View.GONE else View.VISIBLE
binding.popupPlaybackActions.visibility = if (popup) View.VISIBLE else View.GONE
binding.popupToolsScroller.visibility = if (popup) View.VISIBLE else View.GONE
if (popup) {
binding.fullScreenButton.visibility = View.GONE
if (binding.topControls.parent !== binding.popupToolsScroller) {
binding.popupToolsScroller.tag = PopupLayoutState(
binding.topControls.layoutParams,
binding.playbackSeekBar.nextFocusUpId
)
(binding.topControls.parent as ViewGroup).removeView(binding.topControls)
binding.popupToolsScroller.addView(
binding.topControls,
FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
)
binding.playbackSeekBar.nextFocusUpId = R.id.popupFullscreenButton
}
} else {
restorePopupTools(binding)
}
}

@JvmStatic
fun update(binding: PlayerBinding, muted: Boolean, hasChannelIdentity: Boolean) {
val context = binding.root.context
val label = when {
hasChannelIdentity && muted -> R.string.channel_playback_unmute
hasChannelIdentity -> R.string.channel_playback_mute
muted -> R.string.unmute
else -> R.string.mute
}
listOf(binding.channelMuteButton, binding.popupMuteButton).forEach {
it.setImageDrawable(AppCompatResources.getDrawable(context, if (muted) R.drawable.ic_volume_off else R.drawable.ic_volume_up))
it.contentDescription = context.getString(label)
it.isActivated = muted
}
binding.switchMute.contentDescription = context.getString(if (muted) R.string.unmute else R.string.mute)
binding.switchMute.isActivated = muted
}

private fun restorePopupTools(binding: PlayerBinding) {
val state = binding.popupToolsScroller.tag as? PopupLayoutState ?: return
binding.popupToolsScroller.removeView(binding.topControls)
binding.playbackWindowRoot.addView(binding.topControls, 0, state.params)
binding.playbackSeekBar.nextFocusUpId = state.seekUp
binding.popupToolsScroller.tag = null
}

private data class PopupLayoutState(val params: ViewGroup.LayoutParams, val seekUp: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ protected void setupElementsVisibility() {
updateListenModeUi(player.getPlaybackPresentationMode());
updateLearningNoteButtonVisibility(player.getCurrentStreamInfo().orElse(null));
binding.switchMute.setVisibility(View.VISIBLE);
ChannelMuteControls.show(binding, false);
binding.playerCloseButton.setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
// Top controls have a large minHeight which is allows to drag the player
// down in fullscreen mode (just larger area to make easy to locate by finger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ protected void setupElementsVisibility() {
binding.videoAdjustmentsButton.setVisibility(View.GONE);
binding.sleepTimerCountdown.setVisibility(View.GONE);
binding.switchMute.setVisibility(View.GONE);
ChannelMuteControls.show(binding, true);
binding.playerCloseButton.setVisibility(View.GONE);
binding.topControls.bringToFront();
binding.topControls.setClickable(false);
Expand Down Expand Up @@ -336,7 +337,9 @@ private void applyPopupVideoSize() {
R.dimen.popup_minimum_width);
final PopupVideoSizing.Size size = PopupVideoSizing.fit(
preferredPopupWidth > 0 ? preferredPopupWidth : popupLayoutParams.width,
screenWidth, screenHeight, minWidth, popupVideoAspectRatio);
screenWidth, screenHeight, minWidth, popupVideoAspectRatio,
context.getResources().getDimensionPixelSize(
R.dimen.player_popup_minimum_controls_height));
if (popupLayoutParams.width == size.getWidth()
&& popupLayoutParams.height == size.getHeight()) {
return;
Expand Down Expand Up @@ -535,7 +538,9 @@ public WindowManager.LayoutParams retrievePopupLayoutParamsFromPrefs() {
final PopupVideoSizing.Size size = PopupVideoSizing.fit(
preferredPopupWidth, screenWidth, screenHeight,
context.getResources().getDimensionPixelSize(R.dimen.popup_minimum_width),
popupVideoAspectRatio);
popupVideoAspectRatio,
context.getResources().getDimensionPixelSize(
R.dimen.player_popup_minimum_controls_height));

final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
size.getWidth(), size.getHeight(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ internal object PopupVideoSizing {
availableWidth: Int,
availableHeight: Int,
minimumWidth: Int,
videoAspectRatio: Float
videoAspectRatio: Float,
minimumHeight: Int = 0
): Size {
val maxWidth = availableWidth.coerceAtLeast(1)
val maxHeight = availableHeight.coerceAtLeast(1)
val effectiveRatio = videoAspectRatio.takeIf { it.isFinite() && it > 0.1f }
?.takeIf { it < 1.0f } ?: (16f / 9f)
val minWidth = minimumWidth.coerceIn(1, maxWidth)
val wantedWidth = requestedWidth.coerceIn(minWidth, maxWidth)
val wantedHeight = (wantedWidth / effectiveRatio).roundToInt().coerceAtLeast(1)
val minHeight = minimumHeight.coerceIn(1, maxHeight)
val wantedHeight = (wantedWidth / effectiveRatio).roundToInt().coerceAtLeast(minHeight)
if (wantedHeight <= maxHeight) {
return Size(wantedWidth, wantedHeight)
}
Expand Down
Loading
Loading