Could you please give me an example about how to the function playbackGoTo?

Could you please give me an example about how to the function playbackGoTo?

I need to playback one camera video from 2019-2-22 8:00 to 2019-2-22 8:30,

then stop the video when finish playing video.

In general you would start playback, listen to the progress and stop when you want the playback to stop.

Are you using Mobile SDK or MIP library?

I am using Mobile SDK, I checked the example provided by Mobile SDK which is for playing live video​, could you please give an exmple for playing histonry video?

https://doc.developer.milestonesys.com/mipsdkmobile/index.html?base=samples/LoginAndShowStreams_5.html&tree=tree_5.html

It says-

The samples can be found under .\XPMobileSdk\Web\Samples\.

When you start, a page appears for login. After you log in successfully, it lists the available cameras on the server. Each camera has its name displayed on top. Live camera stream starts after you click on a camera. Playback mode is activated after you click on the camera for a second time. In that mode, you can decide to play video backwards or forwards by clicking on the control buttons. You can return to live stream mode by clicking on the “Live” (left arrow) button.

I need play history vieo,it is not live video, how to change live video into history video with a specific time in this sample, Could you please tell me how to do or give me an example?​

Hi Honghai,

Usually “play history video” is called playback.

Therefore Bo has given you a link to the sample that demonstrates both Live and Playback.

In the sample can be seen how to start video streams of both types.

As well as how to control playback speed (playing forward, backward and stop).

Looking at the sample you will notice that all the commands to the MIP SDK Mobile are executed trough calls of “XPMobileSDK.”.

So you can open XPMobileSDK.js file and look for appropriate commands. All of them are commented well.

in order to seek to particular time, you can use:

/**
	 * Sends a ChangeStream command to the server. Goes to the closest possible match of specific time.
	 * 
	 * @method playbackGoTo
	 * @param {VideoConnection} videoConnection - existing VideoConnection object representing a camera stream
	 * @param {Number} millisecondsSinceUnixEpoch - Time of playback speed (in milliseconds since Unix epoch). Valid if SeekType == Time
	 * @param {String} seekType - optional, 'Time' (default), 'TimeOrBefore', 'TimeOrAfter'
	 * @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
	 * @param {Function} errorCallback - function that is called when the command execution has failed and the error is passed as a parameter.
	 * 
	 * @return {ConnectionRequest} - the ConnectionRequest object
	 */
	function playbackGoTo(videoConnection, millisecondsSinceUnixEpoch, seekType, successCallback, errorCallback) {
	    return XPMobileSDK.library.Connection.playbackGoTo(videoConnection, millisecondsSinceUnixEpoch, seekType, successCallback, errorCallback);
	}

In order to stop playback at particular time, you have to make client side logic.

It is not supported by the Mobile server.

You have to check the video frames timestamps and decide when to stop the playback.

Look at the

frame.timestamp

field of the

function videoConnectionReceivedFrame(frame) {
}

callback , called from the SDK on every received frame.

Dear Petar,

can you send me a working example for playback on a specific time? I tried calling the playbackGoTo function in sample.js in the switchToPlayback function but it doesn’t work. Please could you send me a working example?

Peter

Hi Peter,

I do not think “switchToPlayback” is the right method of doing it.

Because, you can see, playbackGoTo method accepts “videoConnection” as first parameter.

Therefore, for test purposes only, I’ve put the call into the “requestStreamCallback”.

By default playback stream starts at the DB end, so I’ve called playbackGoTo with very early timestamp and expected playback to move to DB start. Which actually happened.

“requestStreamCallback” Looks like this right now:

	    function requestStreamCallback(videoConnection) {
	        videoController = videoConnection;
	        videoConnection.addObserver(videoConnectionObserver);
	        videoConnection.open();
 
                // some code in between
 
		var date = new Date(2018, 1, 1, 0, 0, 0, 0);
		XPMobileSDK.playbackGoTo(videoConnection, date.getTime(), 'Time');
	    }

Hi Petar,

i tried the code you sent by putting it in sample.js file, still the camera is loading with live view.

I would also like to know - if we have a calendar where I will select the date and time and a button on click of which the camera should load with the playback from the date and time selected. For this how would the code look like?

Thank you,

Peter

In order this additional call to work you have to create playback stream anyway. Having sample in mind - just click one more time on the already loaded live video - it should switch to playback.

Btw what version of the SDK are you using? I’ve tested it on the latest one.

If you are looking for some Date-Time picker (UI component), that is available trough the MIP SDK Mobile - there isn’t such. You have to implement it by yourself.

Hi Petar,

Once I clicked on the live it changed to playback. But I want to load at the first itself in the playback mode on a specific date, how can we do this?

Peter

Peter,

Please look at the sample a little bit more deeply.

It is a sample after all - it cannot fit to all of your needs. You need to modify it in order to achieve what you want. Opening video stream happens with trigger of RequestStream command first. In the sample is shown how to start Live and Playback streams - the difference is in one parameter passed to the server. It is called “SignalType” and could have values “Live” and “Playback”:

function RequestStreamParams(cameraId, signalType) {
    return {
        CameraId: cameraId,
        DestWidth: 800,
        DestHeight: 600,
        SignalType: signalType /*'Live' or 'Playback'*/,
        MethodType: 'Push' /*'Pull'*/,
        Fps: 25, // This doesn't work for Pull mode, but we have to supply it anyway to keep the server happy
        ComprLevel: 71,
        KeyFramesOnly: 'No' /*'Yes'*/, // Server will give only key frame thumb nails. This will reduce FPS
        RequestSize: 'Yes',
        StreamType: 'Transcoded'
    };
}
 
	    var streamRequest = XPMobileSDK.RequestStream(RequestStreamParams(Id, 'Live'), requestStreamCallback, function (error) { } );
 
	        streamRequest = XPMobileSDK.RequestStream(RequestStreamParams(Id, 'Playback'), requestStreamCallback, null);

If you open XPMobileSDK.js you can see very useful comments on the commands. I’ll pass you some of them here:

	/**
     * Starts live, payback or push video session for a particular device.
     * 
     * @method RequestStream
     * @param {Object} params - Parameters to sent to the server. May contain:
     * <pre>
     * - {String} StreamType - Shows if this is a transcoded or a direct stream. 
     *                         Possible values - Native and Transcoded. Missing 
     *                         of this will be interpreted as Transcoded. (backward compatibility)
     * - {String} CameraId - ID of the camera, which stream is requested (GUID)
     * - {Number} DestWidth - Width of the requested video (in pixels)
     * - {Number} DestHeight - Height of the requested video (in pixels)
     * - {Number} Fps - Frame-rate of the requested video (frames per second)
     * - {Number} ComprLevel - Compression level of the received JPEG images (1 - 100)
     * - {String} SignalType - Type of the requested signal - Live, Playback or Upload.
     * - {String} KeyFramesOnly - Yes/No (everything different than Yes is interpreted as No)
     *                            - reduces stream quality by transcoding only Key (I) frames,
     *                            if option is enabled in the Management Plug-in.
     * ...
     * - {String} SeekType - (optional) Makes seek of specific type: DbStart, 
     *                       DbEnd, PrevSeq, NextSeq, PrevFrame, NextFrame, Time, TimeOrBefore, 
     *                       TimeOrAfter, TimeAfter, TimeBefore.
     * - {String} Time - (optional) Time of playback speed (in milliseconds 
     *                   since Unix epoch). Valid if SeekType == Time.
     * ...
     * </pre>
	 * @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
	 * @param {Function} failCallback - function that is called when the command execution has failed and the error is passed as a parameter.
     */
	function RequestStream(params, successCallback, failCallback) {
	    XPMobileSDK.library.Connection.RequestStream(params, successCallback, failCallback);
	}

You can see there are two additional parameters that are possible to be passed - SeekType and Time. they are the same as those used in the “playbackGoTo” command. If you specify them on the RequestStream command, your playback stream will be positioned on the exact (nearest) time that you provided.

Hi Petar,

i get error code 29 in XPMobileSDK.RequestStream function. This is happening when I call this function multiple times but with different playback times. What could be the reason?

Hi Peter,

Error code 29 states - “PlaybackStreamsLimitReached”.

Calling multiple times “RequestStream” will open (and leave them open for a while) many playback video streams.

If that is the desired action you could check for the limitation in the Mobile Server Management plug-in (Mobile server settings in the Management client, in particular “Performance” tab).

Otherwise you could use “playbackGoTo” in order to change current play time of the current playback steam.

(Leaving multiple video steams open in the mobile server could significant decrease server performance.)

Hi Petar,

if I enable for multiple open streams from Performance tab, will this affect the performance for persons who are using xProtect smart client(windows application)?

Also I would like to know - do we have an option to make the RequestStream function synchronous?

Peter

Hi Peter,

In general it will not.

It should only affect all the users connected trough the mobile server - via Web and Mobile clients.

Of course if VMS is installed all-in-one (e.g. all the services on a single machine) and because of the increased CPU of the Mobile server there are not enough resources for RS to serve video to other clients (SC, MC) - yes SC (Smart Client) could be affected.