mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
audio quality and format settings
This commit is contained in:
parent
11efe9e764
commit
3e28c3d9ce
@ -160,7 +160,7 @@ class PlayerFragment : Fragment() {
|
|||||||
private var watchPositionsEnabled = true
|
private var watchPositionsEnabled = true
|
||||||
private var useSystemCaptionStyle = true
|
private var useSystemCaptionStyle = true
|
||||||
private var seekIncrement = 5L
|
private var seekIncrement = 5L
|
||||||
private var videoFormatPreference = "WEBM"
|
private var videoFormatPreference = "webm"
|
||||||
private var defRes = ""
|
private var defRes = ""
|
||||||
private var bufferingGoal = 50000
|
private var bufferingGoal = 50000
|
||||||
private var seekBarPreview = false
|
private var seekBarPreview = false
|
||||||
@ -287,7 +287,7 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
videoFormatPreference = PreferenceHelper.getString(
|
videoFormatPreference = PreferenceHelper.getString(
|
||||||
PreferenceKeys.PLAYER_VIDEO_FORMAT,
|
PreferenceKeys.PLAYER_VIDEO_FORMAT,
|
||||||
"WEBM"
|
"webm"
|
||||||
)!!
|
)!!
|
||||||
|
|
||||||
defRes = PreferenceHelper.getString(
|
defRes = PreferenceHelper.getString(
|
||||||
@ -1319,7 +1319,8 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
for (vid in response.videoStreams!!) {
|
for (vid in response.videoStreams!!) {
|
||||||
// append quality to list if it has the preferred format (e.g. MPEG)
|
// append quality to list if it has the preferred format (e.g. MPEG)
|
||||||
if (vid.format.equals(videoFormatPreference) && vid.url != null) { // preferred format
|
val preferredMimeType = "video/$videoFormatPreference"
|
||||||
|
if (vid.url != null && vid.mimeType == preferredMimeType) { // preferred format
|
||||||
videosNameArray += vid.quality.toString()
|
videosNameArray += vid.quality.toString()
|
||||||
videosUrlArray += vid.url!!.toUri()
|
videosUrlArray += vid.url!!.toUri()
|
||||||
} else if (vid.quality.equals("LBRY") && vid.format.equals("MP4")) { // LBRY MP4 format
|
} else if (vid.quality.equals("LBRY") && vid.format.equals("MP4")) { // LBRY MP4 format
|
||||||
@ -1410,7 +1411,7 @@ class PlayerFragment : Fragment() {
|
|||||||
exoPlayer.setMediaItem(mediaItem)
|
exoPlayer.setMediaItem(mediaItem)
|
||||||
} else {
|
} else {
|
||||||
val videoUri = videosUrlArray[which]
|
val videoUri = videosUrlArray[which]
|
||||||
val audioUrl = PlayerHelper.getMostBitRate(response.audioStreams!!)
|
val audioUrl = PlayerHelper.getAudioSource(response.audioStreams!!)
|
||||||
setMediaSource(videoUri, audioUrl)
|
setMediaSource(videoUri, audioUrl)
|
||||||
}
|
}
|
||||||
exoPlayer.seekTo(lastPosition)
|
exoPlayer.seekTo(lastPosition)
|
||||||
@ -1431,7 +1432,7 @@ class PlayerFragment : Fragment() {
|
|||||||
// search for quality preference in the available stream sources
|
// search for quality preference in the available stream sources
|
||||||
if (pipedStream.contains(defRes)) {
|
if (pipedStream.contains(defRes)) {
|
||||||
val videoUri = videosUrlArray[index]
|
val videoUri = videosUrlArray[index]
|
||||||
val audioUrl = PlayerHelper.getMostBitRate(streams.audioStreams!!)
|
val audioUrl = PlayerHelper.getAudioSource(streams.audioStreams!!)
|
||||||
setMediaSource(videoUri, audioUrl)
|
setMediaSource(videoUri, audioUrl)
|
||||||
playerBinding.qualityText.text = videosNameArray[index]
|
playerBinding.qualityText.text = videosNameArray[index]
|
||||||
return
|
return
|
||||||
@ -1453,7 +1454,7 @@ class PlayerFragment : Fragment() {
|
|||||||
// if nothing found, use the first list entry
|
// if nothing found, use the first list entry
|
||||||
if (videosUrlArray.isNotEmpty()) {
|
if (videosUrlArray.isNotEmpty()) {
|
||||||
val videoUri = videosUrlArray[0]
|
val videoUri = videosUrlArray[0]
|
||||||
val audioUrl = PlayerHelper.getMostBitRate(streams.audioStreams!!)
|
val audioUrl = PlayerHelper.getAudioSource(streams.audioStreams!!)
|
||||||
setMediaSource(videoUri, audioUrl)
|
setMediaSource(videoUri, audioUrl)
|
||||||
playerBinding.qualityText.text = videosNameArray[0]
|
playerBinding.qualityText.text = videosNameArray[0]
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@ object PreferenceKeys {
|
|||||||
const val DEFAULT_RESOLUTION = "default_res"
|
const val DEFAULT_RESOLUTION = "default_res"
|
||||||
const val BUFFERING_GOAL = "buffering_goal"
|
const val BUFFERING_GOAL = "buffering_goal"
|
||||||
const val SEEKBAR_PREVIEW = "seekbar_preview"
|
const val SEEKBAR_PREVIEW = "seekbar_preview"
|
||||||
|
const val PLAYER_AUDIO_FORMAT = "player_audio_format"
|
||||||
|
const val PLAYER_AUDIO_QUALITY = "player_audio_quality"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download
|
* Download
|
||||||
|
@ -3,13 +3,35 @@ package com.github.libretube.util
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.accessibility.CaptioningManager
|
import android.view.accessibility.CaptioningManager
|
||||||
import com.github.libretube.obj.PipedStream
|
import com.github.libretube.obj.PipedStream
|
||||||
|
import com.github.libretube.preferences.PreferenceHelper
|
||||||
|
import com.github.libretube.preferences.PreferenceKeys
|
||||||
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
||||||
|
|
||||||
object PlayerHelper {
|
object PlayerHelper {
|
||||||
private val TAG = "PlayerHelper"
|
private val TAG = "PlayerHelper"
|
||||||
|
|
||||||
|
// get the audio source following the users preferences
|
||||||
|
fun getAudioSource(audios: List<PipedStream>): String {
|
||||||
|
val audioFormat = PreferenceHelper.getString(PreferenceKeys.PLAYER_AUDIO_FORMAT, "all")
|
||||||
|
val audioQuality = PreferenceHelper.getString(PreferenceKeys.PLAYER_AUDIO_QUALITY, "best")
|
||||||
|
|
||||||
|
val mutableAudios = audios.toMutableList()
|
||||||
|
if (audioFormat != "all") {
|
||||||
|
audios.forEach {
|
||||||
|
val audioMimeType = "audio/$audioFormat"
|
||||||
|
if (it.mimeType != audioMimeType) mutableAudios.remove(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (audioQuality == "worst") {
|
||||||
|
getLeastBitRate(mutableAudios)
|
||||||
|
} else {
|
||||||
|
getMostBitRate(mutableAudios)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get the best bit rate from audio streams
|
// get the best bit rate from audio streams
|
||||||
fun getMostBitRate(audios: List<PipedStream>): String {
|
private fun getMostBitRate(audios: List<PipedStream>): String {
|
||||||
var bitrate = 0
|
var bitrate = 0
|
||||||
var audioUrl = ""
|
var audioUrl = ""
|
||||||
audios.forEach {
|
audios.forEach {
|
||||||
@ -21,6 +43,19 @@ object PlayerHelper {
|
|||||||
return audioUrl
|
return audioUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the best bit rate from audio streams
|
||||||
|
private fun getLeastBitRate(audios: List<PipedStream>): String {
|
||||||
|
var bitrate = 1000000000
|
||||||
|
var audioUrl = ""
|
||||||
|
audios.forEach {
|
||||||
|
if (it.bitrate != null && it.bitrate!! < bitrate) {
|
||||||
|
bitrate = it.bitrate!!
|
||||||
|
audioUrl = it.url.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return audioUrl
|
||||||
|
}
|
||||||
|
|
||||||
// get the system default caption style
|
// get the system default caption style
|
||||||
fun getCaptionStyle(context: Context): CaptionStyleCompat {
|
fun getCaptionStyle(context: Context): CaptionStyleCompat {
|
||||||
val captioningManager =
|
val captioningManager =
|
||||||
|
10
app/src/main/res/drawable/ic_music.xml
Normal file
10
app/src/main/res/drawable/ic_music.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?android:attr/colorControlNormal"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M12,3v10.55c-0.59,-0.34 -1.27,-0.55 -2,-0.55 -2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4V7h4V3h-6z" />
|
||||||
|
</vector>
|
@ -690,11 +690,16 @@
|
|||||||
<item>450</item>
|
<item>450</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="playerVideoFormats">
|
<string-array name="playerVideoFormat">
|
||||||
<item>WEBM</item>
|
<item>WEBM</item>
|
||||||
<item>MPEG_4</item>
|
<item>MPEG_4</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="playerVideoFormatValues">
|
||||||
|
<item>webm</item>
|
||||||
|
<item>mpeg</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="seekIncrement">
|
<string-array name="seekIncrement">
|
||||||
<item>5s</item>
|
<item>5s</item>
|
||||||
<item>10s</item>
|
<item>10s</item>
|
||||||
@ -733,4 +738,26 @@
|
|||||||
<item>never</item>
|
<item>never</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="playerAudioFormat">
|
||||||
|
<item>@string/all</item>
|
||||||
|
<item>OPUS</item>
|
||||||
|
<item>M4A</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="playerAudioFormatValues">
|
||||||
|
<item>all</item>
|
||||||
|
<item>webm</item>
|
||||||
|
<item>mp4</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="audioQuality">
|
||||||
|
<item>@string/best_quality</item>
|
||||||
|
<item>@string/worst_quality</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="audioQualityValues">
|
||||||
|
<item>best</item>
|
||||||
|
<item>worst</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -260,4 +260,8 @@
|
|||||||
<string name="playingOnBackground">Playing on background …</string>
|
<string name="playingOnBackground">Playing on background …</string>
|
||||||
<string name="caption_settings">Caption settings</string>
|
<string name="caption_settings">Caption settings</string>
|
||||||
<string name="downloading_apk">Downloading Apk …</string>
|
<string name="downloading_apk">Downloading Apk …</string>
|
||||||
|
<string name="playerAudioFormat">Audio format for player</string>
|
||||||
|
<string name="playerAudioQuality">Audio quality</string>
|
||||||
|
<string name="best_quality">Best quality</string>
|
||||||
|
<string name="worst_quality">Worst quality</string>
|
||||||
</resources>
|
</resources>
|
@ -13,15 +13,33 @@
|
|||||||
app:title="@string/defres"
|
app:title="@string/defres"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:icon="@drawable/ic_headphones"
|
||||||
|
app:defaultValue="best"
|
||||||
|
app:entries="@array/audioQuality"
|
||||||
|
app:entryValues="@array/audioQualityValues"
|
||||||
|
app:key="player_audio_quality"
|
||||||
|
app:title="@string/playerAudioQuality"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:icon="@drawable/ic_videocam"
|
android:icon="@drawable/ic_videocam"
|
||||||
app:defaultValue="WEBM"
|
app:defaultValue="webm"
|
||||||
app:entries="@array/playerVideoFormats"
|
app:entries="@array/playerVideoFormat"
|
||||||
app:entryValues="@array/playerVideoFormats"
|
app:entryValues="@array/playerVideoFormatValues"
|
||||||
app:key="player_video_format"
|
app:key="player_video_format"
|
||||||
app:title="@string/playerVideoFormat"
|
app:title="@string/playerVideoFormat"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:icon="@drawable/ic_music"
|
||||||
|
app:defaultValue="all"
|
||||||
|
app:entries="@array/playerAudioFormat"
|
||||||
|
app:entryValues="@array/playerAudioFormatValues"
|
||||||
|
app:key="player_audio_format"
|
||||||
|
app:title="@string/playerAudioFormat"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory app:title="@string/player">
|
<PreferenceCategory app:title="@string/player">
|
||||||
|
Loading…
Reference in New Issue
Block a user