The two versions of AudioPlaybackResolver
are similar, but there are several notable differences between them. Here is a detailed analysis of the changes:
1. Change in stream extraction methods
-
Old version:
- Uses
getNonTorrentStreams(info.getAudioStreams())
to retrieve audio streams. - If no audio stream is available, it uses
getNonTorrentStreams(info.getVideoStreams())
to retrieve a video stream to be used as an audio source.
- Uses
-
New version:
- Uses
getFilteredAudioStreams(context, info.getAudioStreams())
to filter the audio streams. - If no audio stream is available, it uses
getPlayableStreams(info.getVideoStreams(), info.getServiceId())
instead ofgetNonTorrentStreams
, which may include different logic for determining usable streams.
- Uses
Impact:
getFilteredAudioStreams
can perform more precise filtering thangetNonTorrentStreams
, potentially improving audio stream selection.getPlayableStreams
may include additional checks related to the service ID (info.getServiceId()
), which could optimize video playback.
2. Addition of audio language management (audioTrack
)
- New version only:
- Introduces a
@Nullable private String audioTrack;
attribute. - Implements the following methods:
@Nullable public String getAudioTrack() { return audioTrack; } public void setAudioTrack(@Nullable final String audioLanguage) { this.audioTrack = audioLanguage; }
- Takes into account
audioTrack
in audio stream selection with:final int audioIndex = ListHelper.getAudioFormatIndex(context, audioStreams, audioTrack);
- Introduces a
Impact:
- Allows selecting an audio stream based on the language set by
setAudioTrack()
, enhancing audio playback customization.
3. Change in MediaItemTag management
- Old version:
final MediaItemTag tag = StreamInfoTag.of(info);
- New version:
final MediaItemTag tag; if (!audioStreams.isEmpty()) { tag = StreamInfoTag.of(info, audioStreams, audioIndex); } else { tag = StreamInfoTag.of(info); }
Impact:
- The new version attaches more information to the
StreamInfoTag
, including audio streams and the selected index, which can enable better tracking of stream metadata.
4. Different handling of cases where no audio stream is found
- Old version:
- Only checks if
audioStreams
orvideoStreams
are empty, without an explicit return condition inresolve()
.
- Only checks if
- New version:
- If no audio or video stream is available, the method immediately returns
null
:if (!videoStreams.isEmpty()) { ... } else { return null; }
- If no audio or video stream is available, the method immediately returns
Impact:
- The new version is more explicit by immediately returning
null
, which can prevent unexpected behaviors.
Summary of key differences:
Aspect | Old version | New version |
---|---|---|
Stream selection | getNonTorrentStreams |
getFilteredAudioStreams and getPlayableStreams |
Audio language management | ❌ | ✅ (with audioTrack ) |
Index selection | getDefaultAudioFormat |
getAudioFormatIndex (takes audioTrack into account) |
Tag management | StreamInfoTag.of(info) |
StreamInfoTag.of(info, audioStreams, audioIndex) (more metadata) |
Error handling | Includes checks but no explicit return | Immediately returns null if no stream is available |
Conclusion
The new version introduces improvements by:
- Better filtering of available streams.
- Adding the ability to select a specific audio track.
- Providing more detailed metadata via
StreamInfoTag
. - Making the code more robust in error handling.
If the goal is to have better audio stream selection with language management and improved filtering logic, the new version is more suitable.
Les deux versions de AudioPlaybackResolver
sont similaires, mais il existe plusieurs différences notables entre elles. Voici une analyse détaillée des changements :
1. Changement des méthodes d'extraction des flux
-
Ancienne version :
- Utilise
getNonTorrentStreams(info.getAudioStreams())
pour récupérer les flux audio. - Si aucun flux audio n'est disponible, elle utilise
getNonTorrentStreams(info.getVideoStreams())
pour récupérer un flux vidéo à utiliser comme source audio.
- Utilise
-
Nouvelle version :
- Utilise
getFilteredAudioStreams(context, info.getAudioStreams())
pour filtrer les flux audio. - Si aucun flux audio n'est disponible, elle utilise
getPlayableStreams(info.getVideoStreams(), info.getServiceId())
au lieu degetNonTorrentStreams
, ce qui peut inclure une logique différente pour déterminer les flux utilisables.
- Utilise
Impact :
getFilteredAudioStreams
peut effectuer un filtrage plus précis quegetNonTorrentStreams
, permettant potentiellement d'améliorer la sélection du flux audio.getPlayableStreams
peut inclure une vérification supplémentaire liée au service ID (info.getServiceId()
), ce qui pourrait optimiser la lecture des vidéos.
2. Ajout de la gestion de la langue audio (audioTrack
)
- Nouvelle version seulement :
- Ajoute un attribut
@Nullable private String audioTrack;
- Implémente les méthodes :
@Nullable public String getAudioTrack() { return audioTrack; } public void setAudioTrack(@Nullable final String audioLanguage) { this.audioTrack = audioLanguage; }
- Prend en compte
audioTrack
dans la sélection du flux audio avec :final int audioIndex = ListHelper.getAudioFormatIndex(context, audioStreams, audioTrack);
- Ajoute un attribut
Impact :
- Permet de sélectionner un flux audio basé sur la langue définie par
setAudioTrack()
, ce qui améliore la personnalisation de la lecture audio.
3. Changement dans la gestion des tags MediaItemTag
- Ancienne version :
final MediaItemTag tag = StreamInfoTag.of(info);
- Nouvelle version :
final MediaItemTag tag; if (!audioStreams.isEmpty()) { tag = StreamInfoTag.of(info, audioStreams, audioIndex); } else { tag = StreamInfoTag.of(info); }
Impact :
- La nouvelle version attache plus d’informations au
StreamInfoTag
, notamment les flux audio et l’index sélectionné, ce qui peut permettre un meilleur suivi des métadonnées du flux.
4. Gestion différente des cas où aucun flux audio n'est trouvé
- Ancienne version :
- Vérifie uniquement si
audioStreams
ouvideoStreams
sont vides, sans condition explicite de retour dansresolve()
.
- Vérifie uniquement si
- Nouvelle version :
- Si aucun flux audio ni vidéo n'est disponible, la méthode retourne immédiatement
null
:if (!videoStreams.isEmpty()) { ... } else { return null; }
- Si aucun flux audio ni vidéo n'est disponible, la méthode retourne immédiatement
Impact :
- La nouvelle version est plus explicite en retournant immédiatement
null
, ce qui peut éviter des comportements inattendus.
Résumé des principales différences :
Aspect | Ancienne version | Nouvelle version |
---|---|---|
Sélection des flux | getNonTorrentStreams |
getFilteredAudioStreams et getPlayableStreams |
Gestion de la langue audio | ❌ | ✅ (avec audioTrack ) |
Sélection de l’index | getDefaultAudioFormat |
getAudioFormatIndex (prend en compte audioTrack ) |
Gestion des tags | StreamInfoTag.of(info) |
StreamInfoTag.of(info, audioStreams, audioIndex) (plus de métadonnées) |
Gestion des erreurs | Implique des vérifications mais pas de retour explicite | Retourne null immédiatement si aucun flux n’est disponible |
Conclusion
La nouvelle version introduit des améliorations en :
- Filtrant mieux les flux disponibles.
- Ajoutant la possibilité de sélectionner une piste audio spécifique.
- Fournissant des métadonnées plus détaillées via
StreamInfoTag
. - Rendant le code plus robuste face aux erreurs.
Si l'objectif est d'avoir une meilleure sélection des flux audio avec la gestion des langues et une logique de filtrage améliorée, la nouvelle version est plus adaptée.