Skip to content
Open
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
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ uglifyjs \
src/ajax.js \
src/ajax-progressive.js \
src/websocket.js \
src/stream.js \
src/ts.js \
src/decoder.js \
src/mpeg1.js \
Expand Down
4 changes: 4 additions & 0 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ var Player = function(url, options) {
this.source = new options.source(url, options);
options.streaming = !!this.source.streaming;
}
else if (url && typeof url.pipe == 'function') {
this.source = new JSMpeg.Source.Stream(url, options);
options.streaming = true;
}
else if (url.match(/^wss?:\/\//)) {
this.source = new JSMpeg.Source.WebSocket(url, options);
options.streaming = true;
Expand Down
63 changes: 63 additions & 0 deletions src/stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
JSMpeg.Source.Stream = (function(){ "use strict";

var StreamSource = function(stream, options) {
this.stream = stream;
this.destination = null;

this.completed = false;
this.established = false;
this.progress = 0;

// Streaming is obiously true when using a stream
this.streaming = true;
};

StreamSource.prototype.connect = function(destination) {
this.destination = destination;
};

StreamSource.prototype.setStream = function(stream) {
if (this.stream) {
this.stream.destroy();
}

this.stream = stream;
this.start();
};

StreamSource.prototype.start = function() {

var that = this;

if (!this.stream) {
return;
}

this.stream.on('data', function onData(chunk) {
that.onLoad(chunk);
});
};

StreamSource.prototype.resume = function(secondsHeadroom) {
// Nothing to do here
};

StreamSource.prototype.destroy = function() {
if (this.stream) {
this.stream.destroy();
}
};

StreamSource.prototype.onLoad = function(data) {
this.established = true;
this.completed = true;
this.progress = 1;

if (this.destination) {
this.destination.write(data);
}
};

return StreamSource;

})();