L'app Android TV potrebbe supportare più tracce audio/testo per diversi lingue e impostazioni dell'audio surround come il ricevitore web app. Per poter supportare più tracce e la selezione delle tracce, devi: implementa quanto segue nell'app Android TV:
Fornisci le informazioni e lo stato del brano
Per i modelli
MediaInfo
,
che fornisce la disponibilità
MediaTracks
utilizzando
MediaInfoModifier
:
val mediaInfoModifier = CastReceiverContext.getInstance() .mediaManager.mediaStatusModifier.mediaInfoModifier mediaInfoModifier.setMediaTracks(Arrays.asList( new MediaTrack.Builder(1, MediaTrack.TYPE_AUDIO) .setName("English") ... build(), new MediaTrack.Builder(2, MediaTrack.TYPE_AUDIO) .setName("Spanish") ... .build() ))
MediaInfoModifier mediaInfoModifier = CastReceiverContext.getInstance() .getMediaManager().getMediaStatusModifier().getMediaInfoModifier(); mediaInfoModifier.setMediaTracks(Arrays.asList( new MediaTrack.Builder(1, MediaTrack.TYPE_AUDIO) .setName("English") ... build(), new MediaTrack.Builder(2, MediaTrack.TYPE_AUDIO) .setName("Spanish") ... .build() ));
Utilizza le funzionalità di
MediaTracksModifier
in base alle tracce attualmente selezionate:
val mediaStatusModifier: MediaTracksModifier = CastReceiverContext.getInstance() .mediaManager.mediaStatusModifier.getMediaTracksModifer() MediaTracksModifier.setActiveTrackIds(longArrayOf(1))
MediaTracksModifier mediaStatusModifier = CastReceiverContext.getInstance() .getMediaManager().getMediaStatusModifier().getMediaTracksModifer(); MediaTracksModifier.setActiveTrackIds(new long[]{1});
I passaggi precedenti consentono di assicurarsi che la finestra di dialogo per la selezione della traccia del mittente rifletta i seguenti valori: lo stato corretto.
Gestire la selezione delle tracce
Per poter selezionare una traccia, devi prima dichiarare
MediaStatus.COMMAND_EDIT_TRACKS
come comando multimediale supportato
MediaStatusModifier
:
CastReceiverContext .getInstance() .getMediaManager() .getMediaStatusModifier() .setMediaCommandSupported(MediaStatus.COMMAND_EDIT_TRACKS, true)
CastReceiverContext .getInstance() .getMediaManager() .getMediaStatusModifier() .setMediaCommandSupported(MediaStatus.COMMAND_EDIT_TRACKS, true);
Quando l'utente seleziona le tracce nella finestra di dialogo di selezione delle tracce sul lato mittente,
l'app Android TV riceve un callback per cambiare i canali selezionati.
Gestire il comando eseguendo l'override
MediaCommandCallback
:
class MyMediaCommandCallback : MediaCommandCallback() { /** Text selection callback scoped to individual track types. */ override fun onSelectTracksByType( senderId: String?, type: Int, tracks: List): Task { return Tasks.call { // Update the track selection in your app. if (type == MediaTrack.TYPE_TEXT) { mySelectTextTracks(tracks) } else if (type == MediaTrack.TYPE_AUDIO) { mySelectAudioTracks(tracks) } // Update the track selection in the modifier to be used in MediaStatus. // This is also scoped to the given track type. mediaStatusModifier.getMediaTracksModifier().setActiveTracksByType( type, tracks ) null } } /** Callback for setting the text track style. */ override fun onSetTextTrackStyle( senderId: String?, textTrackStyle: TextTrackStyle ): Task { return Tasks.call { // Update the track style in your app. mySetTextTrackStyle(textTrackStyle) // Update the track style in the modifier. mediaStatusModifier.setTextTrackStyle(textTrackStyle) null } } // Override the following callback in case you want to handle the original // request. This is strongly not recommended. // // The default implementation automatically translates into // onSelectTracksByType() and onSetTextTrackStyle(). override fun onEditTracksInfo( senderId: String?, editTracksInfoData: EditTracksInfoData ): Task { ... } // Override the following callback in case you want to handle the original // request. This is strongly not recommended. override fun onEditAudioTracks( senderId: String?, editAudioTracksData: EditAudioTracksData ): Task { ... } }
public class MyMediaCommandCallback extends MediaCommandCallback { /** Text selection callback scoped to individual track types. */ @Override public TaskonSelectTracksByType( String senderId, int type, List tracks) { return Tasks.call(() -> { // Update the track selection in your app. if (type == MediaTrack.TYPE_TEXT) { mySelectTextTracks(tracks); } else if (type == MediaTrack.TYPE_AUDIO) { mySelectAudioTracks(tracks); } // Update the track selection in the modifier to be used in MediaStatus. // This is also scoped to the given track type. mediaStatusModifier.getMediaTracksModifier().setActiveTracksByType( type, tracks); return null; }); } /** Callback for setting the text track style. */ @Override public Task onSetTextTrackStyle( String senderId, TextTrackStyle textTrackStyle) { return Tasks.call(() -> { // Update the track style in your app. mySetTextTrackStyle(textTrackStyle); // Update the track style in the modifier. mediaStatusModifier.setTextTrackStyle(textTrackStyle); return null; }); } // Override the following callback in case you want to handle the original // request. This is strongly not recommended. // // The default implementation automatically translates into // onSelectTracksByType() and onSetTextTrackStyle(). @Override public Task onEditTracksInfo( String senderId, EditTracksInfoData editTracksInfoData) { ... } // Override the following callback in case you want to handle the original // request. This is strongly not recommended. @Override public Task onEditAudioTracks( String senderId, EditAudioTracksData editAudioTracksData) { ... } }