Search in sources :

Example 66 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class TtmlDecoder method parseCellResolution.

private static CellResolution parseCellResolution(XmlPullParser xmlParser, CellResolution defaultValue) throws SubtitleDecoderException {
    String cellResolution = xmlParser.getAttributeValue(TTP, "cellResolution");
    if (cellResolution == null) {
        return defaultValue;
    }
    Matcher cellResolutionMatcher = CELL_RESOLUTION.matcher(cellResolution);
    if (!cellResolutionMatcher.matches()) {
        Log.w(TAG, "Ignoring malformed cell resolution: " + cellResolution);
        return defaultValue;
    }
    try {
        int columns = Integer.parseInt(Assertions.checkNotNull(cellResolutionMatcher.group(1)));
        int rows = Integer.parseInt(Assertions.checkNotNull(cellResolutionMatcher.group(2)));
        if (columns == 0 || rows == 0) {
            throw new SubtitleDecoderException("Invalid cell resolution " + columns + " " + rows);
        }
        return new CellResolution(columns, rows);
    } catch (NumberFormatException e) {
        Log.w(TAG, "Ignoring malformed cell resolution: " + cellResolution);
        return defaultValue;
    }
}
Also used : Matcher(java.util.regex.Matcher) SubtitleDecoderException(com.google.android.exoplayer2.text.SubtitleDecoderException)

Example 67 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class TtmlNode method getRegionOutputText.

private static SpannableStringBuilder getRegionOutputText(String resolvedRegionId, Map<String, Cue.Builder> regionOutputs) {
    if (!regionOutputs.containsKey(resolvedRegionId)) {
        Cue.Builder regionOutput = new Cue.Builder();
        regionOutput.setText(new SpannableStringBuilder());
        regionOutputs.put(resolvedRegionId, regionOutput);
    }
    return (SpannableStringBuilder) Assertions.checkNotNull(regionOutputs.get(resolvedRegionId).getText());
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) SpannableStringBuilder(android.text.SpannableStringBuilder) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 68 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class TtmlNode method getCues.

public List<Cue> getCues(long timeUs, Map<String, TtmlStyle> globalStyles, Map<String, TtmlRegion> regionMap, Map<String, String> imageMap) {
    List<Pair<String, String>> regionImageOutputs = new ArrayList<>();
    traverseForImage(timeUs, regionId, regionImageOutputs);
    TreeMap<String, Cue.Builder> regionTextOutputs = new TreeMap<>();
    traverseForText(timeUs, false, regionId, regionTextOutputs);
    traverseForStyle(timeUs, globalStyles, regionMap, regionId, regionTextOutputs);
    List<Cue> cues = new ArrayList<>();
    // Create image based cues.
    for (Pair<String, String> regionImagePair : regionImageOutputs) {
        @Nullable String encodedBitmapData = imageMap.get(regionImagePair.second);
        if (encodedBitmapData == null) {
            // Image reference points to an invalid image. Do nothing.
            continue;
        }
        byte[] bitmapData = Base64.decode(encodedBitmapData, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapData, /* offset= */
        0, bitmapData.length);
        TtmlRegion region = Assertions.checkNotNull(regionMap.get(regionImagePair.first));
        cues.add(new Cue.Builder().setBitmap(bitmap).setPosition(region.position).setPositionAnchor(Cue.ANCHOR_TYPE_START).setLine(region.line, Cue.LINE_TYPE_FRACTION).setLineAnchor(region.lineAnchor).setSize(region.width).setBitmapHeight(region.height).setVerticalType(region.verticalType).build());
    }
    // Create text based cues.
    for (Map.Entry<String, Cue.Builder> entry : regionTextOutputs.entrySet()) {
        TtmlRegion region = Assertions.checkNotNull(regionMap.get(entry.getKey()));
        Cue.Builder regionOutput = entry.getValue();
        cleanUpText((SpannableStringBuilder) Assertions.checkNotNull(regionOutput.getText()));
        regionOutput.setLine(region.line, region.lineType);
        regionOutput.setLineAnchor(region.lineAnchor);
        regionOutput.setPosition(region.position);
        regionOutput.setSize(region.width);
        regionOutput.setTextSize(region.textSize, region.textSizeType);
        regionOutput.setVerticalType(region.verticalType);
        cues.add(regionOutput.build());
    }
    return cues;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Cue(com.google.android.exoplayer2.text.Cue) Bitmap(android.graphics.Bitmap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Nullable(androidx.annotation.Nullable) Pair(android.util.Pair)

Example 69 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class TrackSelectionView method onTrackViewClicked.

private void onTrackViewClicked(View view) {
    isDisabled = false;
    TrackInfo trackInfo = (TrackInfo) Assertions.checkNotNull(view.getTag());
    int groupIndex = trackInfo.groupIndex;
    int trackIndex = trackInfo.trackIndex;
    SelectionOverride override = overrides.get(groupIndex);
    Assertions.checkNotNull(mappedTrackInfo);
    if (override == null) {
        // Start new override.
        if (!allowMultipleOverrides && overrides.size() > 0) {
            // Removed other overrides if we don't allow multiple overrides.
            overrides.clear();
        }
        overrides.put(groupIndex, new SelectionOverride(groupIndex, trackIndex));
    } else {
        // An existing override is being modified.
        int overrideLength = override.length;
        int[] overrideTracks = override.tracks;
        boolean isCurrentlySelected = ((CheckedTextView) view).isChecked();
        boolean isAdaptiveAllowed = shouldEnableAdaptiveSelection(groupIndex);
        boolean isUsingCheckBox = isAdaptiveAllowed || shouldEnableMultiGroupSelection();
        if (isCurrentlySelected && isUsingCheckBox) {
            // Remove the track from the override.
            if (overrideLength == 1) {
                // The last track is being removed, so the override becomes empty.
                overrides.remove(groupIndex);
            } else {
                int[] tracks = getTracksRemoving(overrideTracks, trackIndex);
                overrides.put(groupIndex, new SelectionOverride(groupIndex, tracks));
            }
        } else if (!isCurrentlySelected) {
            if (isAdaptiveAllowed) {
                // Add new track to adaptive override.
                int[] tracks = getTracksAdding(overrideTracks, trackIndex);
                overrides.put(groupIndex, new SelectionOverride(groupIndex, tracks));
            } else {
                // Replace existing track in override.
                overrides.put(groupIndex, new SelectionOverride(groupIndex, trackIndex));
            }
        }
    }
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo) CheckedTextView(android.widget.CheckedTextView)

Example 70 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class TrackSelectionView method updateViewStates.

private void updateViewStates() {
    disableView.setChecked(isDisabled);
    defaultView.setChecked(!isDisabled && overrides.size() == 0);
    for (int i = 0; i < trackViews.length; i++) {
        SelectionOverride override = overrides.get(i);
        for (int j = 0; j < trackViews[i].length; j++) {
            if (override != null) {
                TrackInfo trackInfo = (TrackInfo) Assertions.checkNotNull(trackViews[i][j].getTag());
                trackViews[i][j].setChecked(override.containsTrack(trackInfo.trackIndex));
            } else {
                trackViews[i][j].setChecked(false);
            }
        }
    }
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)

Aggregations

Nullable (androidx.annotation.Nullable)28 Format (com.google.android.exoplayer2.Format)10 ArrayList (java.util.ArrayList)9 MediaItem (com.google.android.exoplayer2.MediaItem)8 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)5 Matcher (java.util.regex.Matcher)5 SuppressLint (android.annotation.SuppressLint)4 Context (android.content.Context)4 Uri (android.net.Uri)4 MediaSource (com.google.android.exoplayer2.source.MediaSource)4 DataSource (com.google.android.exoplayer2.upstream.DataSource)4 StatsDataSource (com.google.android.exoplayer2.upstream.StatsDataSource)4 Activity (android.app.Activity)3 Intent (android.content.Intent)3 SQLException (android.database.SQLException)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 Bundle (android.os.Bundle)3 CallbackMediaItem (androidx.media2.common.CallbackMediaItem)3 C (com.google.android.exoplayer2.C)3 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)3