Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.    
  3. DeviceDetection = function ()
  4. {
  5.     this.construct = function (userAgent) {
  6.         "undefined" == typeof userAgent && (userAgent = navigator.userAgent);
  7.         this.userAgent = userAgent;
  8.         this.checks = {
  9.             iphone:             Boolean(userAgent.match(/iPhone/)),
  10.             ipod:               Boolean(userAgent.match(/iPod/)),
  11.             ipad:               Boolean(userAgent.match(/iPad/)),
  12.             blackberry:         Boolean(userAgent.match(/BlackBerry/)),
  13.             playbook:           Boolean(userAgent.match(/PlayBook/)),
  14.             android:            Boolean(userAgent.match(/Android/)),
  15.             macOS:              Boolean(userAgent.match(/Mac OS X/)),
  16.             win:                Boolean(userAgent.match(/Windows/)),
  17.             mac:                Boolean(userAgent.match(/Macintosh/)),
  18.             wphone:             Boolean(userAgent.match(/(Windows Phone OS|Windows CE|Windows Mobile)/)),
  19.             mobile:             Boolean(userAgent.match(/Mobile/)),
  20.             androidTablet:      Boolean(userAgent.match(/(GT-P1000|SGH-T849|SHW-M180S)/)),
  21.             tabletPc:           Boolean(userAgent.match(/Tablet PC/)),
  22.             palmDevice:         Boolean(userAgent.match(/(PalmOS|PalmSource| Pre\/)/)),
  23.             kindle:             Boolean(userAgent.match(/(Kindle)/)),
  24.             otherMobileHints:   Boolean(userAgent.match(/(Opera Mini|IEMobile|SonyEricsson|smartphone)/))
  25.         }
  26.     };
  27.     this.isTouchDevice = function () {
  28.         return this.checks.iphone || this.checks.ipod || this.checks.ipad
  29.     };
  30.     this.isApple = function () {
  31.         return this.checks.iphone || this.checks.ipod || this.checks.ipad || this.checks.macOS || this.checks.mac
  32.     };
  33.     this.isIOS = function () {
  34.         return this.checks.iphone || this.checks.ipod || this.checks.ipad
  35.     };
  36.     this.isBlackberry = function () {
  37.         return this.checks.blackberry
  38.     };
  39.     this.isAndroid = function () {
  40.         return this.checks.android
  41.     };
  42.     this.isTablet = function () {
  43.         return this.checks.ipad || this.checks.tabletPc || this.checks.playbook || this.checks.androidTablet || this.checks.kindle
  44.     };
  45.     this.isDesktop = function () {
  46.         return !this.isTouchDevice() && !this.isSmartPhone() && !this.isTablet()
  47.     };
  48.     this.isSmartPhone = function () {
  49.         return (this.checks.mobile || this.checks.blackberry || this.checks.palmDevice || this.checks.otherMobileHints) && !this.isTablet() && !this.checks.ipod
  50.     };
  51.     this.construct();
  52.     return this
  53. };
  54.  
  55. PlayLiveStreamOnDesktop = function (params)
  56. {        
  57.     jwplayer(params.container_id).setup({                                      
  58.             'file':     'rtmp://' + params.service_identifier + '/live/_definst_/' + params.stream_name,
  59.             'width':    params.width,
  60.             'height':   params.height,            
  61.     });    
  62. }
  63.  
  64. PlayLiveStreamOnIOS = function (params)
  65. {
  66.     $('#' + params.container_id).html($('<video/>', {
  67.         'src':      'http://' + params.service_identifier + '/live/_definst_/' + params.stream_name + '/playlist.m3u8',
  68.         'style':    'width: ' + params.width + 'px; height: ' +  params.height + 'px; display: block;',
  69.         'text':     'Your browser does not support the video tag.'     ,
  70.         'controls': true
  71.     }));            
  72. }
  73.  
  74. PlayLiveStreamOnAndroid = function (params)
  75. {
  76.     $('#' + params.container_id).html($('<a/>', {
  77.         'src':      'rtsp://' + params.service_identifier + '/live/_definst_/' + params.stream_name,
  78.         'style':    'width: ' + params.width + 'px; height: ' +  params.height + 'px; display: block;',
  79.         'text':     'Your browser does not support the video tag.',
  80.         'controls': true
  81.     }));    
  82.    
  83. }
  84.  
  85. PlayVideoOnDesktop = function (params)
  86. {        
  87.     jwplayer(params.container_id).setup({                                      
  88.             'file':     'rtmp://' + params.service_identifier + '/live/_definst_/' + params.video_format + ':' + params.stream_name,
  89.             'width':    params.width,
  90.             'height':   params.height            
  91.     });    
  92. }
  93.  
  94. PlayVideoOnIOS = function (params)
  95. {
  96.     $('#' + params.container_id).html($('<video/>', {
  97.         'src':      'http://' + params.service_identifier + '/live/_definst_/' + params.video_format + ':' + params.stream_name + '/playlist.m3u8',
  98.         'style':    'width: ' + params.width + 'px; height: ' +  params.height + 'px; display: block;',
  99.         'text':     'Your browser does not support the video tag.',
  100.         'controls': true
  101.     }));            
  102. }
  103.  
  104. PlayVideoOnAndroid = function (params)
  105. {
  106.     $('#' + params.container_id).html($('<video/>', {
  107.         'src':      'rtsp://' + params.service_identifier + '/live/_definst_/' + params.video_format + ':' + params.stream_name,
  108.         'style':    'width: ' + params.width + 'px; height: ' +  params.height + 'px; display: block;',
  109.         'text':     'Your browser does not support the video tag.',
  110.         'controls': true
  111.     }));
  112. }
  113.  
  114. CDNsunLiveStreamWrapper = function (params)
  115. {    
  116.     detection = DeviceDetection();    
  117.     if(detection.isDesktop)
  118.     {
  119.         PlayLiveStreamOnDesktop(params);
  120.     }
  121.     else if(detection.isIOS())
  122.     {
  123.         PlayLiveStreamOnIOS(params);
  124.     }
  125.     else if(detection.isAndroid())
  126.     {        
  127.         PlayLiveStreamOnAndroid(params);
  128.     }
  129.     else
  130.     {
  131.         alert('Unsupported device');
  132.     }
  133. }
  134.  
  135.     $(document).ready(function(){        
  136.         CDNsunLiveStreamWrapper({
  137.             'container_id': "live",
  138.             'service_identifier': "81.20.17.30:1935",
  139.             'stream_name': 'krsu.stream',
  140.             'video_format': 'mp4',
  141.             'width': 100%,
  142.             'height': 420
  143.         });
  144.     });
  145. </script>
  146.  
  147. <div id="live"></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement