{"action":"created","issue":{"url":"https://api.github.com/repos/google/ExoPlayer/issues/514","labels_url":"https://api.github.com/repos/google/ExoPlayer/issues/514/labels{/name}","comments_url":"https://api.github.com/repos/google/ExoPlayer/issues/514/comments","events_url":"https://api.github.com/repos/google/ExoPlayer/issues/514/events","html_url":"https://github.com/google/ExoPlayer/issues/514","id":84090522,"number":514,"title":"Ability to switch audio track during playback","user":{"login":"IanDBird","id":165482,"avatar_url":"https://avatars.githubusercontent.com/u/165482?v=3","gravatar_id":"","url":"https://api.github.com/users/IanDBird","html_url":"https://github.com/IanDBird","followers_url":"https://api.github.com/users/IanDBird/followers","following_url":"https://api.github.com/users/IanDBird/following{/other_user}","gists_url":"https://api.github.com/users/IanDBird/gists{/gist_id}","starred_url":"https://api.github.com/users/IanDBird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IanDBird/subscriptions","organizations_url":"https://api.github.com/users/IanDBird/orgs","repos_url":"https://api.github.com/users/IanDBird/repos","events_url":"https://api.github.com/users/IanDBird/events{/privacy}","received_events_url":"https://api.github.com/users/IanDBird/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/google/ExoPlayer/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-06-02T16:16:18Z","updated_at":"2015-06-17T10:08:11Z","closed_at":null,"body":"I'm attempting to add support to our video player that allows individual audio tracks to be selected during playback. Initially i'm focussing on my ExtractorRendererBuilder (with MP4s) but this really affects any media which can contain multiple different audio tracks.\r\n\r\n#### First Issue\r\n\r\n`MediaCodecAudioTrackRenderer` by default will select, and use, the first audio track provided by the `SampleSource`. It therefore seemed appropriate to extend this class and override the `handlesMimeType` used during `onPrepare` in order to try and \"select\" the audio stream that you want. A problem then arrises that \"mimeType\" is not a unique identifier within a video. For example, you could easily have an MP4 which has 2 AAC tracks, the main feature vs the directors commentary. In order to make it easier to identify individual tracks, it might be worth considering including the `trackIndex` into the method, for example:\r\n\r\n```\r\nprotected boolean handlesMimeType(int trackIndex, String mimeType)\r\n```\r\n\r\nWith this change in place, it should then be possible to create N individual audio track renderers (one for each known audio track), and to disable / enable them on demand.\r\n\r\n#### Second Issue\r\n\r\nThere are two possible (related) issues with what I described above:\r\n - Are there any overheads associated with having lots of separate instances of `MediaCodecAudioTrackRenderer`?\r\n - What if you don't know up front how many audio tracks are available?\r\n\r\nThe audio tracks are available via the `SampleSource` but this is prepared after the `MediaCodecAudioTrackRenderer`'s have been created. I therefore looked at what it would take to have a single `MediaCodecAudioTrackRenderer` that when we needed to \"change\" it (because we needed to select a new track index) we would attempt to re-use the original `SampleSource` but create a new instance of the audio track renderer. However, there doesn't appear to be any way to replace/substitute a new track renderer like this. As mentioned in my approach above, the `handlesMimeType` is called when being prepared. However, if you call the `ExoPlayer.prepare` a second time it will dispose of all the original renderers and eventually their `SampleSource` (that we're trying to re-use).\r\n\r\nIs there something that i'm missing on how best to implement this? "},"comment":{"url":"https://api.github.com/repos/google/ExoPlayer/issues/comments/112744448","html_url":"https://github.com/google/ExoPlayer/issues/514#issuecomment-112744448","issue_url":"https://api.github.com/repos/google/ExoPlayer/issues/514","id":112744448,"user":{"login":"ojw28","id":7881572,"avatar_url":"https://avatars.githubusercontent.com/u/7881572?v=3","gravatar_id":"","url":"https://api.github.com/users/ojw28","html_url":"https://github.com/ojw28","followers_url":"https://api.github.com/users/ojw28/followers","following_url":"https://api.github.com/users/ojw28/following{/other_user}","gists_url":"https://api.github.com/users/ojw28/gists{/gist_id}","starred_url":"https://api.github.com/users/ojw28/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ojw28/subscriptions","organizations_url":"https://api.github.com/users/ojw28/orgs","repos_url":"https://api.github.com/users/ojw28/repos","events_url":"https://api.github.com/users/ojw28/events{/privacy}","received_events_url":"https://api.github.com/users/ojw28/received_events","type":"User","site_admin":false},"created_at":"2015-06-17T10:08:10Z","updated_at":"2015-06-17T10:08:10Z","body":"This request is unrelated to HLS. Multi-audio in HLS is tracked by #73."}}