import { Stream } from './Stream';
import { MediaMetadata } from './MediaMetadata';
import { Subtitle } from './Subtitle';
import { PreloadedSubtitle } from '../../models/PreloadedSubtitle';
import { toByteArray } from 'base64-js';
var Media = /** @class */ (function () {
    function Media(config, subtitleResolver) {
        this._config = config;
        this._subtitleResolver = subtitleResolver;
    }
    Media.prototype.getPingIntervals = function () {
        return this._config.preload.config.pingBackIntervals;
    };
    Media.prototype.isAutoPlay = function () {
        return this._config.isAutoPlay;
    };
    Media.prototype.getStartTime = function () {
        return this._config.startTime;
    };
    Media.prototype.getId = function () {
        return this._config.preload.mediaMetadata.mediaId;
    };
    Media.prototype.getMetadata = function () {
        return new MediaMetadata(this._config.preload.mediaMetadata);
    };
    Media.prototype.getStream = function () {
        return new Stream(this._config.preload.streamInfo);
    };
    Media.prototype.getNextVideoUrl = function () {
        return this._config.nextUrl;
    };
    Media.prototype.getSubtitles = function () {
        var subtitles = [];
        var preload = this._config.preload;
        var items = preload.subtitles.items;
        var preloadedData = preload.subtitle;
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            if (item.id === preloadedData.id) {
                var iv = toByteArray(preloadedData.iv);
                var data = toByteArray(preloadedData.data);
                var content = this._subtitleResolver.getSubtitle(preloadedData.id, iv, data);
                subtitles.push(new PreloadedSubtitle(content, item.id, item.title, item.author, item.isDefault, item.delay));
            }
            else {
                subtitles.push(new Subtitle(this._subtitleResolver, item.url, item.id, item.title, item.author, item.isDefault, item.delay));
            }
        }
        return subtitles;
    };
    return Media;
}());
export { Media };
//# sourceMappingURL=Media.js.map