Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surface EXT-X-STREAM-INF's CLOSED_CAPTIONS=NONE #485

Merged
merged 1 commit into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/org/mangui/hls/model/Level.as
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package org.mangui.hls.model {
public var codec_h264 : Boolean;
/** Level Bitrate. **/
public var bitrate : uint;
/** captions . **/
public var closed_captions : String;
/** Level Name. **/
public var name : String;
/** level index (sorted by bitrate) **/
Expand Down
2 changes: 2 additions & 0 deletions src/org/mangui/hls/playlist/Manifest.as
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ package org.mangui.hls.playlist {
}
} else if (param.indexOf('AUDIO') > -1) {
level.audio_stream_id = (param.split('=')[1] as String).replace(replacedoublequote, "").replace(trimwhitespace, "");
} else if (param.indexOf('CLOSED-CAPTIONS') > -1) {
level.closed_captions = (param.split('=')[1] as String).replace(replacedoublequote, "").replace(trimwhitespace, "");
} else if (param.indexOf('NAME') > -1) {
level.name = (param.split('=')[1] as String).replace(replacedoublequote, "");
}
Expand Down
3 changes: 3 additions & 0 deletions src/org/mangui/osmf/plugins/HLSMediaElement.as
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
var audioTrait : AudioTrait = new NetStreamAudioTrait(_stream);
addTrait(MediaTraitType.AUDIO, audioTrait);

var ccTrait : HLSClosedCaptionsTrait = new HLSClosedCaptionsTrait(_hls);
addTrait(HLSMediaTraitType.CLOSED_CAPTIONS, ccTrait);

var bufferTrait : BufferTrait = new HLSBufferTrait(_hls);
addTrait(MediaTraitType.BUFFER, bufferTrait);

Expand Down
9 changes: 9 additions & 0 deletions src/org/mangui/osmf/plugins/traits/HLSClosedCaptionsState.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.mangui.osmf.plugins.traits
{
public final class HLSClosedCaptionsState
{
public static const YES:String = "yes";
public static const NO:String = "no";
public static const UNKNOWN:String = "unknown";
}
}
58 changes: 58 additions & 0 deletions src/org/mangui/osmf/plugins/traits/HLSClosedCaptionsTrait.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mangui.osmf.plugins.traits {
import org.mangui.hls.HLS;
import org.mangui.hls.event.HLSEvent;
import org.mangui.hls.model.Level;
import org.osmf.traits.MediaTraitBase;

CONFIG::LOGGING {
import org.mangui.hls.utils.Log;
}

public class HLSClosedCaptionsTrait extends MediaTraitBase {
private var _hls : HLS;
private var _hasClosedCapations : String;

public function HLSClosedCaptionsTrait(hls : HLS, closed_captions : String = HLSClosedCaptionsState.UNKNOWN) {
CONFIG::LOGGING {
Log.debug("HLSClosedCaptionsTrait()");
}
super(HLSMediaTraitType.CLOSED_CAPTIONS);

_hasClosedCapations = closed_captions;
_hls = hls;
_hls.addEventListener(HLSEvent.LEVEL_SWITCH, _levelSwitchHandler);
}

override public function dispose() : void {
CONFIG::LOGGING {
Log.debug("HLSClosedCaptionsTrait:dispose");
}
_hls.removeEventListener(HLSEvent.LEVEL_SWITCH, _levelSwitchHandler);
super.dispose();
}

public function hasClosedCaptions() : String {
return _hasClosedCapations;
}

/** Update playback position/duration **/
private function _levelSwitchHandler(event : HLSEvent) : void {
var cc : String = (_hls.levels[event.level] as Level).closed_captions;

if (cc && cc === "NONE")
{
// manifest told us to ignore any 608/708 binary
_hasClosedCapations = HLSClosedCaptionsState.NO;
}
else
{
_hasClosedCapations = HLSClosedCaptionsState.UNKNOWN;
}

// YES only happens for WebVTT, which isn't supported.
}
}
}
7 changes: 7 additions & 0 deletions src/org/mangui/osmf/plugins/traits/HLSMediaTraitType.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.mangui.osmf.plugins.traits
{
public final class HLSMediaTraitType
{
public static const CLOSED_CAPTIONS:String = "hlsClosedCaptions";
}
}