Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from SRGSSR/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
StaehliJ authored Apr 13, 2018
2 parents 47275c7 + 0456968 commit b619f45
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'de.felixschulze.gradle:gradle-hockeyapp-plugin:3.2'
}
}
Expand All @@ -29,7 +29,7 @@ ext {
buildToolsVersion = '26.0.1'

//libs
supportLibraryVersion = '26.0.1'
supportLibraryVersion = '27.1.0'
SRGLibraryVersion = '1.4.314@aar'
SRGSnapLibraryVersion = '1.4.246-SNAPSHOT@aar'
androidSupportTest = '0.5'
Expand Down
1 change: 0 additions & 1 deletion srgmediaplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.minSdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ public void run() {
}

private static Segment createSegment(String identifier, long markIn, long markOut, boolean blocked) {
return new Segment(identifier, null, null, null, blocked ? "blocked" : null, markIn, markOut, markOut - markIn, 0, true, false);
return new Segment(identifier, null, null, null, blocked ? "blocked" : null, markIn, markOut, markOut - markIn, 0, true, false, false);
}
}
56 changes: 56 additions & 0 deletions srgmediaplayer/src/main/java/ch/srg/mediaplayer/AudioTrack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ch.srg.mediaplayer;

import android.support.annotation.Nullable;

import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.TrackGroup;

/**
* Helper to manage ExoPlayer AudioTrack
*/
public class AudioTrack {
public final int groupIndex;
public final int trackIndex;
public final String trackId;
public final String language;


public AudioTrack(int groupIndex, int trackIndex, String trackId, String language) {
this.groupIndex = groupIndex;
this.trackIndex = trackIndex;
this.trackId = trackId;
this.language = language;
}

@Nullable
public static AudioTrack createFrom(TrackGroup trackGroup, int groupIndex, int trackIndex) {
Format format = trackGroup.getFormat(trackIndex);
if (format.id != null && format.language != null) {
return new AudioTrack(groupIndex, trackIndex, format.id, format.language);
} else {
return null;
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AudioTrack that = (AudioTrack) o;

if (trackIndex != that.trackIndex || groupIndex != that.groupIndex) return false;
if (trackId != null ? !trackId.equals(that.trackId) : that.trackId != null) return false;
return language != null ? language.equals(that.language) : that.language == null;

}

@Override
public int hashCode() {
int result = Integer.valueOf(groupIndex).hashCode();
result = 31 * result + Integer.valueOf(trackIndex).hashCode();
result = 31 * result + (trackId != null ? trackId.hashCode() : 0);
result = 31 * result + (language != null ? language.hashCode() : 0);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public enum Type {
DID_UNBIND_FROM_PLAYER_VIEW,

SUBTITLE_DID_CHANGE,
AUDIO_TRACK_DID_CHANGE,

FIRST_FRAME_RENDERED,

Expand Down Expand Up @@ -1680,9 +1681,17 @@ public Long getCurrentBandwidth() {
}

public boolean hasVideoTrack() {
return hasTrackOfType(C.TRACK_TYPE_VIDEO);
}

public boolean hasAudioTrack() {
return hasTrackOfType(C.TRACK_TYPE_AUDIO);
}

private boolean hasTrackOfType(int trackType) {
TrackSelectionArray currentTrackSelections = exoPlayer.getCurrentTrackSelections();
for (int i = 0; i < currentTrackSelections.length; i++) {
if (exoPlayer.getRendererType(i) == C.TRACK_TYPE_VIDEO) {
if (exoPlayer.getRendererType(i) == trackType) {
if (currentTrackSelections.get(i) != null) {
return true;
}
Expand All @@ -1695,6 +1704,75 @@ public Throwable getFatalError() {
return fatalError;
}

@NonNull
public List<AudioTrack> getAudioTrackList() {
List<AudioTrack> result = new ArrayList<>();
MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
int audioTrackRendererId = getAudioTrackRendererId();
if (mappedTrackInfo != null && audioTrackRendererId != -1) {
TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(audioTrackRendererId);
for (int trackGroupIndex = 0; trackGroupIndex < trackGroups.length; trackGroupIndex++) {
TrackGroup trackGroup = trackGroups.get(trackGroupIndex);
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
AudioTrack audioTrack = AudioTrack.createFrom(trackGroup, trackGroupIndex, trackIndex);
if (audioTrack != null) {
result.add(audioTrack);
}
}
}
}
if (debugMode && (result.isEmpty())) {
return Arrays.asList(
new AudioTrack(0, 0, "English", null),
new AudioTrack(0, 1, "French", null),
new AudioTrack(0, 2, "عربي", null),
new AudioTrack(0, 3, "中文", null));
} else {
return result;
}
}

/**
* If track is null, no sound is playing during playback.
*
* @param track
*/
public void setAudioTrack(@Nullable AudioTrack track) {
int rendererIndex = getAudioTrackRendererId();
MappingTrackSelector.MappedTrackInfo trackInfo = trackSelector.getCurrentMappedTrackInfo();
if (rendererIndex != -1 && trackInfo != null) {
TrackGroupArray trackGroups = trackInfo.getTrackGroups(rendererIndex);
trackSelector.setRendererDisabled(rendererIndex, track == null);
if (track != null) {
TrackSelection.Factory factory = new FixedTrackSelection.Factory();
MappingTrackSelector.SelectionOverride override = new MappingTrackSelector.SelectionOverride(factory, track.groupIndex, track.trackIndex);
trackSelector.setSelectionOverride(rendererIndex, trackGroups, override);
} else {
trackSelector.clearSelectionOverride(rendererIndex, trackGroups);
}
}
broadcastEvent(Event.Type.AUDIO_TRACK_DID_CHANGE);
}

@Nullable
public AudioTrack getCurrentAudioTrack() {
int rendererIndex = getAudioTrackRendererId();

MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
if (mappedTrackInfo != null && rendererIndex != -1) {
TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);

MappingTrackSelector.SelectionOverride override = trackSelector.getSelectionOverride(rendererIndex, trackGroups);
if (override != null) {
int[] tracks = override.tracks;
if (tracks.length != 0) {
return AudioTrack.createFrom(trackGroups.get(override.groupIndex), override.groupIndex, tracks[0]);
}
}
}
return null;
}

@NonNull
public List<SubtitleTrack> getSubtitleTrackList() {
List<SubtitleTrack> result = new ArrayList<>();
Expand Down Expand Up @@ -1779,12 +1857,20 @@ private SubtitleTrack getSubtitleTrackByTrackId(int i, int j) {
}

private int getSubtitleRendererId() {
return getTrackRendererIdOfType(C.TRACK_TYPE_TEXT);
}

private int getAudioTrackRendererId() {
return getTrackRendererIdOfType(C.TRACK_TYPE_AUDIO);
}

private int getTrackRendererIdOfType(int trackType) {
MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();

if (mappedTrackInfo != null) {
for (int i = 0; i < mappedTrackInfo.length; i++) {
if (mappedTrackInfo.getTrackGroups(i).length > 0
&& exoPlayer.getRendererType(i) == C.TRACK_TYPE_TEXT) {
&& exoPlayer.getRendererType(i) == trackType) {
return i;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* License information is available from the LICENSE file.
*/
public class Segment implements Comparable<Segment> {

private String identifier;
private String title;
private String description;
Expand All @@ -21,10 +20,11 @@ public class Segment implements Comparable<Segment> {
private long publishedTimestamp;
private boolean displayable;
private boolean isLive;
private boolean is360;

public Segment(String identifier, String title, String description, String imageUrl,
String blockingReason, long markIn, long markOut, long duration, long publishedTimestamp,
boolean displayable, boolean isLive) {
boolean displayable, boolean isLive, boolean is360) {
this.identifier = identifier;
this.title = title;
this.description = description;
Expand All @@ -36,6 +36,7 @@ public Segment(String identifier, String title, String description, String image
this.publishedTimestamp = publishedTimestamp;
this.displayable = displayable;
this.isLive = isLive;
this.is360 = is360;
}

public String getTitle() {
Expand Down Expand Up @@ -109,6 +110,7 @@ public boolean equals(Object o) {
if (publishedTimestamp != segment.publishedTimestamp) return false;
if (displayable != segment.displayable) return false;
if (isLive != segment.isLive) return false;
if (is360 != segment.is360) return false;
if (identifier != null ? !identifier.equals(segment.identifier) : segment.identifier != null)
return false;
if (title != null ? !title.equals(segment.title) : segment.title != null) return false;
Expand All @@ -133,6 +135,7 @@ public int hashCode() {
result = 31 * result + (int) (publishedTimestamp ^ (publishedTimestamp >>> 32));
result = 31 * result + (displayable ? 1 : 0);
result = 31 * result + (isLive ? 1 : 0);
result = 31 * result + (is360 ? 1 : 0);
return result;
}

Expand All @@ -151,10 +154,15 @@ public String toString() {
", publishedTimestamp=" + publishedTimestamp +
", displayable=" + displayable +
", isLive=" + isLive +
", is360=" + is360 +
'}';
}

public boolean isLive() {
return isLive;
}

public boolean is360() {
return is360;
}
}
1 change: 0 additions & 1 deletion srgmediaplayertestutils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ repositories {

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.minSdkVersion
Expand Down

0 comments on commit b619f45

Please sign in to comment.