Skip to content

Commit 7f9916b

Browse files
authored
Fix/dash callback events (Dash-Industry-Forum#4722)
* Fix DASH callback event mechanism. CommonMediaRequest and CommonMediaResponse objects were missing * Adjust XHR call in ThumbnailTracks.js to use commonMediaRequest and commonMediaResponse * Fix code style
1 parent d31387d commit 7f9916b

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

src/streaming/controllers/EventController.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import Debug from '../../core/Debug.js';
3434
import EventBus from '../../core/EventBus.js';
3535
import MediaPlayerEvents from '../../streaming/MediaPlayerEvents.js';
3636
import XHRLoader from '../net/XHRLoader.js';
37+
import CommonMediaRequest from '../vo/CommonMediaRequest.js';
38+
import CommonMediaResponse from '../vo/CommonMediaResponse.js';
3739

3840
function EventController() {
3941

@@ -549,13 +551,16 @@ function EventController() {
549551
function _sendCallbackRequest(url) {
550552
try {
551553
let loader = XHRLoader(context).create({});
552-
loader.load({
553-
method: 'get',
554-
url: url,
555-
request: {
556-
responseType: 'arraybuffer'
554+
const commonMediaRequest = new CommonMediaRequest(
555+
{
556+
method: 'get',
557+
url: url,
558+
responseType: 'arraybuffer',
559+
customData: {}
557560
}
558-
});
561+
);
562+
const commonMediaResponse = new CommonMediaResponse({ request: commonMediaRequest });
563+
loader.load(commonMediaRequest, commonMediaResponse);
559564
} catch (e) {
560565
logger.error(e);
561566
}

src/streaming/net/XHRLoader.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ function XHRLoader() {
7474
commonMediaResponse.headers = Utils.parseHttpHeaders(this.getAllResponseHeaders());
7575
commonMediaResponse.data = this.response;
7676
}
77-
xhr.onloadend = commonMediaRequest.customData.onloadend;
78-
xhr.onprogress = commonMediaRequest.customData.onprogress;
79-
xhr.onabort = commonMediaRequest.customData.onabort;
80-
xhr.ontimeout = commonMediaRequest.customData.ontimeout;
77+
if (commonMediaRequest.customData) {
78+
xhr.onloadend = commonMediaRequest.customData.onloadend;
79+
xhr.onprogress = commonMediaRequest.customData.onprogress;
80+
xhr.onabort = commonMediaRequest.customData.onabort;
81+
xhr.ontimeout = commonMediaRequest.customData.ontimeout;
82+
}
8183

8284
xhr.send();
8385

src/streaming/thumbnail/ThumbnailTracks.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import BoxParser from '../../streaming/utils/BoxParser.js';
3838
import XHRLoader from '../../streaming/net/XHRLoader.js';
3939
import DashHandler from '../../dash/DashHandler.js';
4040
import SegmentsController from '../../dash/controllers/SegmentsController.js';
41+
import CommonMediaRequest from '../vo/CommonMediaRequest.js';
42+
import CommonMediaResponse from '../vo/CommonMediaResponse.js';
4143

4244
function ThumbnailTracks(config) {
4345
const context = this.context;
@@ -192,27 +194,31 @@ function ThumbnailTracks(config) {
192194
representation.segments.some((ss) => {
193195
if (ss.mediaStartTime <= time && ss.mediaStartTime + ss.duration > time) {
194196
const baseURL = baseURLController.resolve(representation.path);
195-
loader.load({
197+
const commonMediaRequest = new CommonMediaRequest({
196198
method: 'get',
197199
url: baseURL.url,
198-
request: {
199-
range: ss.mediaRange,
200-
responseType: 'arraybuffer'
201-
},
202-
onload: function (e) {
203-
let info = boxParser.getSamplesInfo(e.target.response);
204-
let blob = new Blob([e.target.response.slice(info.sampleList[0].offset, info.sampleList[0].offset + info.sampleList[0].size)], { type: 'image/jpeg' });
205-
let imageUrl = window.URL.createObjectURL(blob);
206-
cache.push({
207-
start: ss.mediaStartTime,
208-
end: ss.mediaStartTime + ss.duration,
209-
url: imageUrl
210-
});
211-
if (callback) {
212-
callback(imageUrl);
200+
responseType: 'arraybuffer',
201+
customData: {
202+
request: {
203+
range: ss.mediaRange,
204+
},
205+
onloadend: function (e) {
206+
let info = boxParser.getSamplesInfo(e.target.response);
207+
let blob = new Blob([e.target.response.slice(info.sampleList[0].offset, info.sampleList[0].offset + info.sampleList[0].size)], { type: 'image/jpeg' });
208+
let imageUrl = window.URL.createObjectURL(blob);
209+
cache.push({
210+
start: ss.mediaStartTime,
211+
end: ss.mediaStartTime + ss.duration,
212+
url: imageUrl
213+
});
214+
if (callback) {
215+
callback(imageUrl);
216+
}
213217
}
214-
}
215-
});
218+
},
219+
})
220+
const commonMediaResponse = new CommonMediaResponse({ request: commonMediaRequest });
221+
loader.load(commonMediaRequest, commonMediaResponse);
216222
return true;
217223
}
218224
});

0 commit comments

Comments
 (0)