jsmpeg
jsmpeg copied to clipboard
url.match is not a function
Hello. I have been using jsmpeg for a while and decided to update it to the newest release. I get a TypeError when calling new JSMpeg.Player()
Uncaught TypeError: url.match is not a function
at new Player (jsmpeg.min.js:1)
at startWebsocket (card.js:63)
at HTMLDocument.
Code lookes like this:
var websocket = new WebSocket(location);
....
var player = new JSMpeg.Player(websocket, {
canvas: canvas,
autoplay: true,
loop: true,
audio: false,
pauseWhenHidden: false,
progressive: true,
videoBufferSize: 524288, //512*1024 (512kb)
onPlay: mpegPlay,
onStalled: mpegStalled,
onSourceEstablished: mpegEstablished
});
You have to call new JSMpeg.Player()
with the WebSocket URL, not a WebSocket instance. E.g.:
var player = new JSMpeg.Player('ws://1.2.3.4/', {...}
Ok. Thanks :) I have used the player with an instance of websocket in earlier version of jsmpeg. I execute some code on websocket events (e.g 'connected' or 'close'). Does the current release support that somehow?
You can probably use the onSourceEstablished
callback in the constructor - this is fired when the connection first receives data.
A close
event is not directly exposed, but you can access the WS connection through the player E.g: player.source.socket.addEventListener('close', onCloseCallback);
.
Keep in mind though that the WS connection automatically tries to reconnect whenever the connection is lost. You can disable this by specifying reconnectInterval: 0
in the constructor.
Hello, I am also trying to use JSMpeg to view video streamed via web-sockets, however I have already established the Web-socket connection in order to control the video start / stop, my requirements go beyond simple start / stop commands.
Could anyone provide an example on how to get JSMpeg to use a web-socket instance in place of a newly instantiated web-socket.
Thanks in advance.
Chrisbarm
Create a new Source
class that meets your requirements (see websocket.js for an example) and instantiate the JSMpeg.Player
with that class:
var MyCustomWebSocketSource = function(socket, options) {
this.socket = socket;
// (...)
};
// Implement the API for this source class:
// .connect(), .write(), .start(), .resume(),
// .established, .complete, .progress
// (again, see websocket.js for an example)
// Create a new player instance with you existing websocket
// and your custom source class:
var player = new JSMpeg.Player(socket, {
source: MyCustomWebSocketSource
});
I will take a look at this.
Thank you very much for you quick response!