1 /* 2 * This is system cordova_plugin (TV specific API). 3 * Apache License (2004). See http://www.apache.org/licenses/LICENSE-2.0 4 * 5 * Copyright (c) 2014, LG Electronics, Inc. 6 */ 7 8 9 /** 10 * This represents the video API itself, and provides a global namespace for operating video service. 11 * @class 12 */ 13 cordova.define('cordova/plugin/video', function (require, exports, module) { // jshint ignore:line 14 15 function log(msg) { 16 // //console.log//will be removed // jshint ignore:line 17 } 18 19 var service; 20 if (window.PalmSystem) { // jshint ignore:line 21 log("Window.PalmSystem Available"); 22 service = require('cordova/plugin/webos/service'); 23 } else { 24 service = { 25 Request : function(uri, params) { 26 log(uri + " invoked. But I am a dummy because PalmSystem is not available"); 27 28 if (typeof params.onFailure === 'function') { 29 params.onFailure({ 30 returnValue:false, 31 errorText:"PalmSystem Not Available. Cordova is not installed?" 32 }); 33 } 34 }}; 35 } 36 37 /** 38 * video interface 39 */ 40 var Video = function () { 41 }; 42 43 44 function checkErrorCodeNText(result, errorCode, errorText) { 45 46 if (result.errorCode === undefined || result.errorCode === null ) { 47 result.errorCode = errorCode; 48 } 49 if (result.errorText ===undefined || result.errorText === null) { 50 result.errorText = errorText; 51 } 52 } 53 54 var platformInfoObj = { 55 webOSVer : -1, 56 chipset : 'undefined' 57 }; 58 function checkPlatformVersion(cb) { 59 60 if (platformInfoObj.webOSVer === -1) { // Not defined yet 61 62 service.Request('luna://com.webos.service.tv.systemproperty', { 63 method: 'getSystemInfo', 64 parameters: { 65 keys: ["sdkVersion", "boardType"] 66 }, 67 onSuccess: function(result) { 68 var temp = result.sdkVersion.split('.'); 69 if (temp.length >= 1 && temp[0] === '1') { 70 platformInfoObj = { 71 webOSVer : 1, 72 chipset : result.boardType.split("_")[0] 73 }; 74 } else if (temp.length >= 1 && temp[0] === '2') { 75 platformInfoObj = { 76 webOSVer : 2, 77 chipset : result.boardType.split("_")[0] 78 }; 79 } else if (temp.length >= 1 && temp[0] === '3') { 80 platformInfoObj = { 81 webOSVer : 3, 82 chipset : result.boardType.split("_")[0] 83 }; 84 } else { 85 platformInfoObj = { 86 webOSVer : 0, 87 chipset : "" 88 }; 89 } 90 cb(platformInfoObj); 91 }, 92 onFailure: function(error) { 93 platformInfoObj = { 94 webOSVer : 0, 95 chipset : "" 96 } 97 cb(platformInfoObj); 98 } 99 }); 100 101 } else { 102 cb(platformInfoObj); 103 } 104 } 105 106 /** 107 * Gets video position and size. 108 * @class Video 109 * @param {Function} successCallback success callback function. 110 * @param {Function} errorCallback failure callback function. 111 * @return {Object} 112 * <div align=left> 113 * <table class="hcap_spec" width=400> 114 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 115 * <tbody> 116 * <tr><th>source</th><th>Object</th><th>source rectangle of video. </th></tr> 117 * <tr><th>source.x</th><th>Number</th><th>The x coordinate of the upper-left corner of the rectangle. </th></tr> 118 * <tr class="odd"><th>source.y</th><th>Number</th><th>The y coordinate of the upper-left corner of the rectangle. </th></tr> 119 * <tr><th>source.width</th><th>Number</th><th>The width of the rectangle. </th></tr> 120 * <tr class="odd"><th>source.height</th><th>Number</th><th>The height of the rectangle. </th></tr> 121 * </tbody> 122 * </table> 123 * 124 * @example 125 * // Javascript code 126 * function getVideoStatus () { 127 * function successCb(cbObject) { 128 * console.log("cbObject : " + JSON.stringify(cbObject.source)); 129 * 130 * console.log("source.x : " + cbObject.source.x); 131 * console.log("source.y : " + cbObject.source.y); 132 * console.log("source.width : " + cbObject.source.width); 133 * console.log("source.height : " + cbObject.source.height); 134 * 135 * // Do something 136 * ... 137 * } 138 * 139 * function failureCb(cbObject) { 140 * var errorCode = cbObject.errorCode; 141 * var errorText = cbObject.errorText; 142 * console.log ("Error Code [" + errorCode + "]: " + errorText); 143 * } 144 * 145 * var video = new Video(); 146 * video.getVideoStatus(successCb, failureCb); 147 * } 148 * @since 1.0 149 * @see 150 * <a href="Video%23setVideoSize.html">Video.setVideoSize()</a><br> 151 */ 152 Video.prototype.getVideoStatus = function (successCallback, errorCallback) { 153 154 log("getVideoStatus: "); 155 156 service.Request("luna://com.webos.service.tv.signage/", { 157 method : "getVideoSize", 158 onSuccess : function(result) { 159 log("getVideoStatus: On Success"); 160 161 if (result.returnValue === true) { 162 if (typeof successCallback === 'function') { 163 var cbObj = {}; 164 cbObj.source = result.videoSize.source; 165 successCallback(cbObj); 166 } 167 } 168 }, 169 onFailure : function(result) { 170 log("getVideoStatus: On Failure"); 171 delete result.returnValue; 172 if (typeof errorCallback === 'function') { 173 checkErrorCodeNText(result, "VGVS", "Video.getVideoStatus returns failure."); 174 errorCallback(result); 175 } 176 } 177 }); 178 179 log("Video.getVideoStatus Done"); 180 181 }; 182 183 Video.currentVideo = { 184 uri : null, 185 source : null, 186 tagId : null 187 }; 188 189 /** 190 * Sets video size.<br> 191 * Original video(source rectangle) will be adjusted to the full screen size. It can be resized or a zoom effect can be applied to the video. 192 * <br> 193 * Note : Using more than one video tag in an html page may not be supported due to hardware limitation. 194 * 195 * @class Video 196 * @param {Function} successCallback success callback function. 197 * @param {Function} errorCallback failure callback function. 198 * @param {Object} options source object vary depending on video resolution. 199 * And rectangle object has boundary value as : <br> 200 * source.x + source.width <= width of video resolution , source.y + source.height <= height of video resolution <br> 201 * x and y value of rectangle are upper than zero. 202 * <br><image src="./image/setVideoSize.png"><br> 203 * <div align=left> 204 * <table class="hcap_spec" width=400> 205 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 206 * <tbody> 207 * <tr><th>source</th><th>Object</th><th>source rectangle of video. </th><th>required</th></tr> 208 * <tr><th>source.x</th><th>Number</th><th>The x coordinate of the upper-left corner of the rectangle. </th><th>required</th></tr> 209 * <tr class="odd"><th>source.y</th><th>Number</th><th>The y coordinate of the upper-left corner of the rectangle. </th><th>required</th></tr> 210 * <tr><th>source.width</th><th>Number</th><th>The width of the rectangle. </th><th>required</th></tr> 211 * <tr class="odd"><th>source.height</th><th>Number</th><th>The height of the rectangle. </th><th>required</th></tr> 212 * </tbody> 213 * </table> 214 * 215 * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br> 216 * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p> 217 * @example 218 * // Javascript code 219 * function setVideoSize () { 220 * var options = {source: {x:10, y:10, width:900, height:600}}; 221 * 222 * function successCb() { 223 * // Do something 224 * } 225 * 226 * function failureCb(cbObject) { 227 * var errorCode = cbObject.errorCode; 228 * var errorText = cbObject.errorText; 229 * console.log ("Error Code [" + errorCode + "]: " + errorText); 230 * } 231 * 232 * var video = new Video(); 233 * video.setVideoSize(successCb, failureCb, options); 234 * } 235 * @since 1.0 236 * @see 237 * <a href="Video%23getVideoStatus.html">Video.getVideoStatus()</a><br> 238 * <a href="InputSource%23initialize.html#constructor">InputSource.initialize()</a><br> 239 */ 240 Video.prototype.setVideoSize = function (successCallback, errorCallback, options) { 241 242 log("setVideoSize: " + JSON.stringify(options)); 243 244 if (options.source === undefined || 245 typeof options.source.x !== 'number' || typeof options.source.y !== 'number' || 246 typeof options.source.width !== 'number' || typeof options.source.height !== 'number' || 247 isNaN(options.source.x) || isNaN(options.source.y) || isNaN(options.source.width) || isNaN(options.source.height) || 248 options.source.x < 0 || options.source.y < 0 || options.source.width <= 0 || options.source.height <= 0 || 249 options.source.width < 16 || options.source.height < 16) { 250 251 if (typeof errorCallback === 'function') { 252 var result = {}; 253 checkErrorCodeNText(result, "VSVS", "Video.setVideoSize returns failure. out of range or type error."); 254 errorCallback(result); 255 } 256 257 return; 258 } 259 260 service.Request("luna://com.webos.service.tv.signage/", { 261 method : "getVideoSize", 262 onSuccess : function(result) { 263 log("setVideoSize: On Success"); 264 265 if (result.returnValue === true) { 266 267 var cbObj = {}; 268 cbObj.x = result.videoSize.destination.x; 269 cbObj.y = result.videoSize.destination.y; 270 cbObj.width = result.videoSize.destination.width; 271 cbObj.height = result.videoSize.destination.height; 272 273 //console.log("current video size : " + JSON.stringify(result.videoSize.source)); 274 //console.log("saved video : " + JSON.stringify(Video.currentVideo)); 275 276 var videoTags = document.getElementsByTagName("video"); // jshint ignore:line 277 var findVideoTags = false; 278 for (var i=0; i<videoTags.length; i++) { 279 //console.log("video tag: " + videoTags[i]); 280 //console.log("video tag:id " + videoTags[i].id); 281 // video tag 282 if (videoTags[i].currentTime > 0) { 283 //console.log("video tag is working"); 284 findVideoTags = true; 285 if (Video.currentVideo.uri !== videoTags[i].src || 286 (videoTags[i].id !== null && 287 videoTags[i].id !== undefined && 288 Video.currentVideo.tagId !== null && 289 Video.currentVideo.tagId !== undefined && 290 Video.currentVideo.tagId !== videoTags[i].id) ) { 291 Video.currentVideo.uri = videoTags[i].src; 292 Video.currentVideo.source = result.videoSize.source; 293 Video.currentVideo.tagId = videoTags[i].id; 294 //console.log("saved new video : " + JSON.stringify(Video.currentVideo)); 295 } 296 break; 297 } 298 } 299 if(findVideoTags === false) { 300 // external input 301 service.Request("luna://com.webos.service.eim/", { 302 method : "getCurrentInput", 303 parameters : {}, 304 onSuccess : function(resultw) { 305 //console.log("current input " + JSON.stringify(resultw)); 306 307 if (resultw.returnValue === true && Video.currentVideo.uri !== resultw.mainInputSourceId || 308 (videoTags[0].id !== null && 309 videoTags[0].id !== undefined 310 && Video.currentVideo.tagId !== null 311 && Video.currentVideo.tagId !== undefined 312 && Video.currentVideo.tagId !== videoTags[0].id) ) { 313 Video.currentVideo.uri = resultw.mainInputSourceId; 314 Video.currentVideo.tagId = (videoTags[0] !== null && videoTags[0].id !== null && videoTags[0].id !== undefined ? videoTags[0].id : null); 315 service.Request("luna://com.webos.service.tv.signage/", { 316 method : "getVideoSize", 317 onSuccess : function(resultx) { 318 log("setVideoSize: On Success 1"); 319 320 if (resultx.returnValue === true) { 321 322 Video.currentVideo.source = resultx.videoSize.source; 323 //console.log("saved new video : " + JSON.stringify(Video.currentVideo)); 324 325 if (resultx.videoSize.source.width === 0 && resultx.videoSize.source.height === 0) { 326 327 Video.currentVideo = { 328 uri : null, 329 source : null, 330 tagId : null 331 }; 332 333 var resultCallBack = {}; 334 checkErrorCodeNText(resultCallBack, "VSVS", "Video.setVideoSize returns failure. Not ready to setVideoSize." ); 335 errorCallback(resultCallBack); 336 return; 337 } else if ( Video.currentVideo.uri === null || Video.currentVideo.source === null || 338 (options.source.width + options.source.x) > (Video.currentVideo.source.x + Video.currentVideo.source.width) || 339 (options.source.height + options.source.y) > (Video.currentVideo.source.y + Video.currentVideo.source.height) ) { 340 341 var resultCallBack2 = {}; 342 checkErrorCodeNText(resultCallBack2, "VSVS", "Video.setVideoSize returns failure. out of range or type error." 343 + "(" + Video.currentVideo.source.width + " : " + Video.currentVideo.source.height + ")"); 344 errorCallback(resultCallBack2); 345 return; 346 347 } 348 349 service.Request("luna://com.webos.service.tv.signage/", { 350 method : "setVideoSize", 351 parameters : { 352 videoSize : { 353 "source": { 354 "x": options.source.x, 355 "y": options.source.y, 356 "width": options.source.width, 357 "height": options.source.height 358 }, 359 "destination": { 360 "x": cbObj.x, 361 "y": cbObj.y, 362 "width": cbObj.width, 363 "height": cbObj.height 364 } 365 } 366 }, 367 onSuccess : function(result) { 368 log("setVideoSize: On Success 2"); 369 370 if (result.returnValue === true && typeof successCallback === 'function') { 371 successCallback(); 372 return; 373 } 374 }, 375 onFailure : function(result) { 376 log("setVideoSize: On Failure 2"); 377 delete result.returnValue; 378 if (typeof errorCallback === 'function') { 379 checkErrorCodeNText(result, "VSVS", "Video.setVideoSize returns failure. Can't current video source size."); 380 errorCallback(result); 381 return; 382 } 383 } 384 }); 385 386 } 387 } 388 }); 389 } else { 390 if ( Video.currentVideo.uri === null || Video.currentVideo.source === null || 391 (options.source.width + options.source.x) > (Video.currentVideo.source.x + Video.currentVideo.source.width) || 392 (options.source.height + options.source.y) > (Video.currentVideo.source.y + Video.currentVideo.source.height) ){ 393 394 var resultCallBack = {}; 395 checkErrorCodeNText(resultCallBack, "VSVS", "Video.setVideoSize returns failure. out of range or type error." 396 + "(" + Video.currentVideo.source.width + " : " + Video.currentVideo.source.height + ")"); 397 errorCallback(resultCallBack); 398 return; 399 } 400 401 service.Request("luna://com.webos.service.tv.signage/", { 402 method : "setVideoSize", 403 parameters : { 404 videoSize : { 405 "source": { 406 "x": options.source.x, 407 "y": options.source.y, 408 "width": options.source.width, 409 "height": options.source.height 410 }, 411 "destination": { 412 "x": cbObj.x, 413 "y": cbObj.y, 414 "width": cbObj.width, 415 "height": cbObj.height 416 } 417 } 418 }, 419 onSuccess : function(result) { 420 log("setVideoSize: On Success 3"); 421 422 if (result.returnValue === true && typeof successCallback === 'function') { 423 successCallback(); 424 return; 425 } 426 }, 427 onFailure : function(result) { 428 log("setVideoSize: On Failure 3"); 429 delete result.returnValue; 430 if (typeof errorCallback === 'function') { 431 checkErrorCodeNText(result, "VSVS", "Video.setVideoSize returns failure. Can't current video source size."); 432 errorCallback(result); 433 return; 434 } 435 } 436 }); 437 } 438 }, 439 onFailure : function(result) { 440 log("setVideoSize: On Failure 3"); 441 delete result.returnValue; 442 if (typeof errorCallback === 'function') { 443 checkErrorCodeNText(result, "VSVS", "Video.setVideoSize returns failure. Can't set current video source size."); 444 errorCallback(result); 445 return; 446 } 447 } 448 }); 449 } else { 450 451 if ( Video.currentVideo.uri === null || Video.currentVideo.source === null || 452 (options.source.width + options.source.x) > (Video.currentVideo.source.x + Video.currentVideo.source.width) || 453 (options.source.height + options.source.y) > (Video.currentVideo.source.y + Video.currentVideo.source.height) ) { 454 455 var resultCallBack = {}; 456 checkErrorCodeNText(resultCallBack, "VSVS", "Video.setVideoSize returns failure. out of range or type error." 457 + "(" + Video.currentVideo.source.width + " : " + Video.currentVideo.source.height + ")"); 458 errorCallback(resultCallBack); 459 return; 460 } 461 462 service.Request("luna://com.webos.service.tv.signage/", { 463 method : "setVideoSize", 464 parameters : { 465 videoSize : { 466 "source": { 467 "x": options.source.x, 468 "y": options.source.y, 469 "width": options.source.width, 470 "height": options.source.height 471 }, 472 "destination": { 473 "x": cbObj.x, 474 "y": cbObj.y, 475 "width": cbObj.width, 476 "height": cbObj.height 477 } 478 } 479 }, 480 onSuccess : function(result) { 481 log("setVideoSize: On Success 4"); 482 483 if (result.returnValue === true && typeof successCallback === 'function') { 484 successCallback(); 485 return; 486 } 487 }, 488 onFailure : function(result) { 489 log("setVideoSize: On Failure 4"); 490 delete result.returnValue; 491 if (typeof errorCallback === 'function') { 492 checkErrorCodeNText(result, "VSVS", "Video.setVideoSize returns failure. Can't current video source size."); 493 errorCallback(result); 494 return; 495 } 496 } 497 }); 498 } 499 500 501 } 502 }, 503 onFailure : function(result) { 504 log("setVideoSize: On Failure"); 505 delete result.returnValue; 506 if (typeof errorCallback === 'function') { 507 checkErrorCodeNText(result, "VSVS", "Video.setVideoSize returns failure."); 508 errorCallback(result); 509 return; 510 } 511 } 512 }); 513 514 log("Video.setVideoSize Done"); 515 }; 516 517 518 /** 519 * Sets content rotation.<br> 520 * <br> 521 * Note :Only full screen video rotation is supported. 522 * 523 * @class Video 524 * @param {Function} successCallback success callback function. 525 * @param {Function} errorCallback failure callback function. 526 * @param {Object} options 527 * 528 * <div align=left> 529 * <table class="hcap_spec" width=400> 530 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 531 * <tbody> 532 * <tr><th>degree</th><th>String</th><th>"off", "90", or "270"</th><th>required</th></tr> 533 * <tr class="odd"><tr><th>aspectRatio</th><th>String</th><th>"full" or "original" </th><th>required</th></tr> 534 * </tbody> 535 * </table> 536 * 537 * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br> 538 * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p> 539 * @example 540 * // Javascript code 541 * function setContentRotation () { 542 * var options = {degree : "90", aspectRatio : "full"}; 543 * 544 * function successCb() { 545 * // Do something 546 * } 547 * 548 * function failureCb(cbObject) { 549 * var errorCode = cbObject.errorCode; 550 * var errorText = cbObject.errorText; 551 * console.log ("Error Code [" + errorCode + "]: " + errorText); 552 * } 553 * 554 * var video = new Video(); 555 * video.setContentRotation(successCb, failureCb, options); 556 * } 557 * @since 1.3 558 * @see 559 * <a href="Video%23getContentRotation.html">Video.getContentRotation()</a><br> 560 */ 561 Video.prototype.setContentRotation = function(successCallback, errorCallback, options) { 562 563 log("setContentRotation: "); 564 565 checkPlatformVersion(function(platformInformation) { 566 567 if (platformInformation.webOSVer === 3) { 568 if (typeof errorCallback === 'function') { 569 var result = {}; 570 checkErrorCodeNText(result, "VSCR", "Video.setContentRotation is not supported in WEBOS 3.0."); 571 errorCallback(result); 572 573 return; 574 } 575 } 576 577 if (typeof options === "undefined" || options === null || 578 (options.degree !== "off" && options.degree !== "90" && options.degree !== "270") || 579 (options.aspectRatio !== "full" && options.aspectRatio != "original")) { 580 581 var result = {}; 582 checkErrorCodeNText(result, "VSCR", "Video.setContentRotation invlalid parameters."); 583 } 584 585 service.Request("luna://com.webos.service.commercial.signage.storageservice/video/", { 586 method: "setContentRotation", 587 parameters: options, 588 onSuccess: function(result) { 589 log("setContentRotation: On Success"); 590 591 if (result.returnValue === true && typeof successCallback === 'function') { 592 successCallback(); 593 return; 594 } 595 }, 596 onFailure: function(result) { 597 log("setContentRotation: On Failure"); 598 delete result.returnValue; 599 if (typeof errorCallback === 'function') { 600 checkErrorCodeNText(result, "VSCR", "Video.setContentRotation returns failure."); 601 errorCallback(result); 602 return; 603 } 604 } 605 }); 606 607 log("Video.setContentRotation: Done "); 608 }); 609 }; 610 611 /** 612 * Gets content rotation status. 613 * @class Video 614 * @param {Function} successCallback success callback function. 615 * @param {Function} errorCallback failure callback function. 616 * @return {Object} 617 * <div align=left> 618 * <table class="hcap_spec" width=400> 619 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 620 * <tbody> 621 * <tr><th>degree</th><th>String</th><th>"off", "90", or "270"</th><th>required</th></tr> 622 * <tr class="odd"><tr><th>aspectRatio</th><th>String</th><th>"full" or "original" </th><th>required</th></tr> 623 * </tbody> 624 * </table> 625 * 626 * @example 627 * // Javascript code 628 * function getContentRotation () { 629 * function successCb(cbObject) { 630 * console.log("cbObject : " + JSON.stringify(cbObject.source)); 631 * 632 * console.log("degree : " + cbObject.degree); 633 * console.log("aspectRatio : " + cbObject.aspectRatio); 634 * 635 * // Do something 636 * } 637 * 638 * function failureCb(cbObject) { 639 * var errorCode = cbObject.errorCode; 640 * var errorText = cbObject.errorText; 641 * console.log ("Error Code [" + errorCode + "]: " + errorText); 642 * } 643 * 644 * var video = new Video(); 645 * video.getContentRotation(successCb, failureCb); 646 * } 647 * @since 1.3 648 * @see 649 * <a href="Video%23setContentRotation.html">Video.setContentRotation()</a><br> 650 */ 651 Video.prototype.getContentRotation = function(successCallback, errorCallback) { 652 653 log("getContentRotation: "); 654 655 checkPlatformVersion(function(platformInformation) { 656 657 if (platformInformation.webOSVer === 3) { 658 if (typeof errorCallback === 'function') { 659 var result = {}; 660 checkErrorCodeNText(result, "VSCR", "Video.getContentRotation is not supported in WEBOS 3.0."); 661 errorCallback(result); 662 663 return; 664 } 665 } 666 667 service.Request("luna://com.webos.service.commercial.signage.storageservice/video/", { 668 method: "getContentRotation", 669 onSuccess: function(result) { 670 log("getContentRotation: On Success"); 671 672 if (result.returnValue === true) { 673 if (typeof successCallback === 'function') { 674 delete result.returnValue; 675 successCallback(result); 676 } 677 } 678 }, 679 onFailure: function(result) { 680 log("getContentRotation: On Failure"); 681 delete result.returnValue; 682 if (typeof errorCallback === 'function') { 683 checkErrorCodeNText(result, "VGCR", "Video.getContentRotation returns failure."); 684 errorCallback(result); 685 } 686 } 687 }); 688 689 log("Video.getContentRotation Done"); 690 }); 691 }; 692 693 /** 694 * Sets output size and position<br> 695 * 696 * @class Video 697 * @param {Function} successCallback success callback function. 698 * @param {Function} errorCallback failure callback function. 699 * @param {Object} options 700 * 701 * <div align=left> 702 * <table class="hcap_spec" width=400> 703 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 704 * <tbody> 705 * <tr><th>x</th><th>String</th><th>Postion of x-axis in video</th><th>required</th></tr> 706 * <tr class="odd"><tr><th>y</th><th>String</th><th>Postion of y-axis in video</th><th>required</th></tr> 707 * <tr><th>width</th><th>String</th><th>Width of size in video</th><th>required</th></tr> 708 * <tr class="odd"><tr><th>height</th><th>String</th><th>Height of size in video</th><th>required</th></tr> 709 * </tbody> 710 * </table> 711 * 712 * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br> 713 * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p> 714 * @example 715 * // Javascript code 716 * function setVideoViewTransform() { 717 * 718 * var successCb = function (){ 719 * // Do Something 720 * } 721 * 722 * var failureCb = function(){ 723 * var errorCode = cbObject.errorCode; 724 * var errorText = cbObject.errorText; 725 * console.log ("Error Code [" + errorCode + "]: " + errorText); 726 * } 727 * 728 * var video = new Video(); 729 730 * video.setVideoViewTransform(successCb, failureCb, { 731 * //Portrait Standard 732 * x: 0, 733 * y: 0, 734 * width: 1920, 735 * height: 600 736 * }); 737 * } 738 * @since 1.3 739 * @see 740 * <a href="Video%23setContentRotation.html">Video.setContentRotation()</a><br> 741 */ 742 Video.prototype.setVideoViewTransform = function(successCallback, failureCallback, options) { 743 if (typeof options.x !== 'number' || typeof options.y !== 'number' || 744 typeof options.width !== 'number'|| typeof options.height !== 'number') { 745 failureCallback({ 746 errorCode : "VSVVT", 747 errorText : "Invalid Parameter type." 748 }); 749 } 750 751 checkPlatformVersion(function(platformInformation) { 752 var BROWSER_WINDOW_WIDTH, BROWSER_WINDOW_HEIGHT; 753 if (platformInformation.webOSVer === 3) { 754 if (typeof failureCallback === 'function') { 755 var result = {}; 756 checkErrorCodeNText(result, "VSVT", "Video.setVideoViewTransform is not supported in WEBOS 3.0."); 757 failureCallback(result); 758 759 return; 760 } 761 } 762 763 if (platformInformation.webOSVer === 2 && platformInformation.chipset === 'H15') { 764 BROWSER_WINDOW_WIDTH = 3840; 765 BROWSER_WINDOW_HEIGHT = 2160; 766 } 767 else { 768 BROWSER_WINDOW_WIDTH = 1920; 769 BROWSER_WINDOW_HEIGHT = 1080; 770 } 771 772 service.Request("luna://com.webos.service.commercial.signage.storageservice/video/", { 773 method: "getMediaID", 774 onSuccess: function(ret) { 775 if (ret.returnValue === true) { 776 var mediaID = ret.id; 777 service.Request("luna://com.webos.service.tv.display/", { 778 method: "setCustomDisplayWindow", 779 parameters: { 780 context : mediaID, 781 sourceInput : { 782 positionX : 0, 783 positionY : 0, 784 width : BROWSER_WINDOW_WIDTH, 785 height : BROWSER_WINDOW_HEIGHT 786 }, 787 displayOutput : { 788 positionX : options.x, 789 positionY : options.y, 790 width : options.width, 791 height : options.height 792 } 793 }, 794 onSuccess: function(ret) { 795 if (ret.returnValue === true) { 796 if (typeof successCallback === "function") { 797 successCallback() 798 } 799 } 800 else { 801 delete ret.returnValue; 802 if (typeof failureCallback === "function") { 803 failureCallback({ 804 errorCode : "VSVT", 805 errorText : "Failed to set video transition" 806 }); 807 808 } 809 } 810 }, 811 onFailure: function(ret) { 812 delete ret.returnValue; 813 if (typeof failureCallback === "function") { 814 failureCallback({ 815 errorCode : "VSVVT", 816 errorText : "Failed to set video transition" 817 }); 818 } 819 } 820 }); 821 } 822 }, 823 onFailure: function(ret) { 824 delete ret.returnValue; 825 if (typeof failureCallback === "function") { 826 failureCallback({ 827 errorCode : "VSVVT", 828 errorText : "Cannot found video area" 829 }); 830 } 831 } 832 }); 833 }); 834 835 }; 836 837 /** 838 * Sets position and size of rotated video.<br> 839 * <br> 840 * Note :<br> 841 * This feature is supported after setting of rotated video by setContentRotation.<br> 842 * 843 * @class Video 844 * @param {Function} successCallback success callback function. 845 * @param {Function} errorCallback failure callback function. 846 * @param {Object} options 847 * <div align=left> 848 * <table class="hcap_spec" width=400> 849 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 850 * <tbody> 851 * <tr><th>x</th><th>String</th><th>Postion of x-axis in video</th><th>required</th></tr> 852 * <tr class="odd"><tr><th>y</th><th>String</th><th>Postion of y-axis in video</th><th>required</th></tr> 853 * <tr><th>width</th><th>String</th><th>Width of size in video</th><th>required</th></tr> 854 * <tr class="odd"><tr><th>height</th><th>String</th><th>Height of size in video</th><th>required</th></tr> 855 * </tbody> 856 * </table> 857 * 858 * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br> 859 * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p> 860 * @example 861 * // Javascript code 862 * function setRotatedVideoTransform() { 863 * var successCb = function (){ 864 * // Do Something 865 * } 866 * 867 * var failureCb = function(cbObject){ 868 * var errorCode = cbObject.errorCode; 869 * var errorText = cbObject.errorText; 870 * console.log ("Error Code [" + errorCode + "]: " + errorText); 871 * } 872 * 873 * var video = new Video(); 874 * 875 * video.setRotatedVideoTransform(successCb, failureCb, { 876 * //Portrait Standard 877 * x: 100, 878 * y: 120, 879 * width: 900, 880 * height: 600 881 * }); 882 * } 883 * @since 1.0 884 * @see 885 * <a href="Video%23setContentRotation.html">Video.setContentRotation()</a><br> 886 */ 887 Video.prototype.setRotatedVideoTransform = function(successCallback, failureCallback, options) { 888 checkPlatformVersion(function(platformInformation) { 889 var BROWSER_WINDOW_WIDTH, BROWSER_WINDOW_HEIGHT; 890 if (platformInformation.webOSVer === 3) { 891 if (typeof failureCallback === 'function') { 892 var result = {}; 893 checkErrorCodeNText(result, "VSRT", "Video.setRotatedVideoTransform is not supported in WEBOS 3.0."); 894 failureCallback(result); 895 896 return; 897 } 898 } 899 900 if (platformInformation.webOSVer === 2 && platformInformation.chipset === 'H15') { 901 BROWSER_WINDOW_WIDTH = 3840; 902 BROWSER_WINDOW_HEIGHT = 2160; 903 } 904 else { 905 BROWSER_WINDOW_WIDTH = 1920; 906 BROWSER_WINDOW_HEIGHT = 1080; 907 } 908 909 if (typeof options.x !== 'number' || 910 typeof options.y !== 'number' || 911 typeof options.width !== 'number' || 912 typeof options.height !== 'number' ) { 913 failureCallback({ 914 errorCode : "VSRVT", 915 errorText : "Invalid Parameter type." 916 }); 917 } 918 919 920 service.Request("luna://com.webos.service.commercial.signage.storageservice/video/", { 921 method: "getContentRotation", 922 onSuccess: function(rotated) { 923 var _x, _y, _w, _h; 924 925 if (rotated.degree === "off") { 926 failureCallback({ 927 errorCode : "VSRVT", 928 errorText : "Content must be applied content rotation first." 929 }); 930 return; 931 } 932 /** 933 * Convert to portrait origin (1080 x 1920) 934 * (0, 1920) (0, 0) 935 * +-------------------+ 936 * | | 937 * | Degree = 90 | 938 * | | 939 * +-------------------+ 940 * (1080, 1920) (1080, 0) 941 */ 942 943 else if (rotated.degree === "90") { 944 _x = BROWSER_WINDOW_WIDTH - (options.y + options.height), 945 _y = options.x, 946 _w = options.height, 947 _h = options.width; 948 } 949 /** 950 * (0, 1080) (1920, 1080) 951 * +-------------------+ 952 * | | 953 * | Degree = 270 | 954 * | | 955 * +-------------------+ 956 * (0, 0) (0, 1920) 957 */ 958 else if (rotated.degree === "270") { 959 _x = options.y, 960 _y = BROWSER_WINDOW_HEIGHT - (options.x + options.width), 961 _w = options.height, 962 _h = options.width; 963 } 964 965 service.Request("luna://com.webos.service.commercial.signage.storageservice/video/", { 966 method: "getMediaID", 967 onSuccess: function(ret) { 968 if (ret.returnValue === true) { 969 var mediaID = ret.id; 970 971 if (platformInformation.webOSVer === 2 && platformInformation.chipset === 'H15') { 972 service.Request("luna://com.webos.service.tv.display/", { 973 method: "setDisplayWindow", 974 parameters: { 975 context : mediaID, 976 fullScreen: false, 977 displayOutput : { 978 positionX : _x, 979 positionY : _y, 980 width : _w, 981 height : _h 982 } 983 }, 984 onSuccess: function(ret) { 985 if (ret.returnValue === true) { 986 if (typeof successCallback === "function") { 987 successCallback(); 988 } 989 } 990 else { 991 delete ret.returnValue; 992 if (typeof failureCallback === "function") { 993 failureCallback({ 994 errorCode : "VSRVT", 995 errorText : "Failed to set video transition" 996 }); 997 998 } 999 } 1000 }, 1001 onFailure: function(ret) { 1002 delete ret.returnValue; 1003 if (typeof failureCallback === "function") { 1004 failureCallback({ 1005 errorCode : "VSRVT", 1006 errorText : "Failed to set video transition: " + ret.errorText 1007 }); 1008 } 1009 } 1010 }); 1011 } 1012 else { 1013 service.Request("luna://com.webos.service.tv.display/", { 1014 method: "setRotateDisplayWindow", 1015 parameters: { 1016 context : mediaID, 1017 fullScreen: false, 1018 displayOutput : { 1019 positionX : _x, 1020 positionY : _y, 1021 width : _w, 1022 height : _h 1023 } 1024 }, 1025 onSuccess: function(ret) { 1026 if (ret.returnValue === true) { 1027 if (typeof successCallback === "function") { 1028 successCallback(); 1029 } 1030 } 1031 else { 1032 delete ret.returnValue; 1033 if (typeof failureCallback === "function") { 1034 failureCallback({ 1035 errorCode : "VSRVT", 1036 errorText : "Failed to set video transition" 1037 }); 1038 1039 } 1040 } 1041 }, 1042 onFailure: function(ret) { 1043 delete ret.returnValue; 1044 if (typeof failureCallback === "function") { 1045 failureCallback({ 1046 errorCode : "VSRVT", 1047 errorText : "Failed to set video transition: " + ret.errorText 1048 }); 1049 } 1050 } 1051 }); 1052 } 1053 } 1054 }, 1055 onFailure: function(ret) { 1056 delete ret.returnValue; 1057 if (typeof failureCallback === "function") { 1058 failureCallback({ 1059 errorCode : "VSRVT", 1060 errorText : "Cannot found video area" 1061 }); 1062 } 1063 } 1064 }); 1065 }, 1066 onFailure: function(err) { 1067 if (typeof failureCallback === "function") { 1068 failureCallback({ 1069 errorCode : "VSRVT", 1070 errorText : "Cannot check content rotation." 1071 }); 1072 } 1073 } 1074 }); 1075 }); 1076 } 1077 1078 module.exports = Video; 1079 }); 1080 1081 Video = cordova.require('cordova/plugin/video'); // jshint ignore:line 1082 1083