blob: b3869e621f0e940973a908e2dff59b8cb18f778c [file] [log] [blame]
// Copyright 2017 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef COBALT_DOM_AUDIO_TRACK_H_
#define COBALT_DOM_AUDIO_TRACK_H_
#include <string>
#include "cobalt/dom/track_base.h"
#include "cobalt/script/wrappable.h"
namespace cobalt {
namespace dom {
class SourceBuffer;
// The AudioTrack interface holds attributes of an audio track.
// https://www.w3.org/TR/html51/semantics-embedded-content.html#audiotrack-audiotrack
class AudioTrack : public TrackBase {
public:
// Custom, not in any spec.
//
AudioTrack(const std::string& id, const std::string& kind,
const std::string& label, const std::string& language,
bool enabled)
: TrackBase(id, kind, label, language, &AudioTrack::IsValidKind),
enabled_(enabled) {}
// Web API: AudioTrack
//
using TrackBase::id;
using TrackBase::kind;
using TrackBase::label;
using TrackBase::language;
bool enabled() const { return enabled_; }
void set_enabled(bool enabled) {
if (enabled_ == enabled) {
return;
}
enabled_ = enabled;
if (media_element_) {
// TODO: Notify the media element.
// media_element_->OnAudioTrackChanged(this);
NOTREACHED();
}
}
// Custom, not in any spec.
//
static bool IsValidKind(const char* kind) {
// https://www.w3.org/TR/html51/semantics-embedded-content.html#dom-audiotrack-audiotrackkind
return strcmp(kind, "alternative") == 0 ||
strcmp(kind, "descriptions") == 0 ||
strcmp(kind, "main") == 0 ||
strcmp(kind, "main-desc") == 0 ||
strcmp(kind, "translation") == 0 ||
strcmp(kind, "commentary") == 0 ||
strlen(kind) == 0;
}
DEFINE_WRAPPABLE_TYPE(AudioTrack);
private:
bool enabled_;
};
} // namespace dom
} // namespace cobalt
#endif // COBALT_DOM_AUDIO_TRACK_H_