addVideo.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <style>
  2. .plusForm div.btn {padding: 0px;}
  3. .plusForm .content div{margin-bottom: 0px;}
  4. #filePicker>.webuploader-pick,#fileVideo>.webuploader-pick{background: none; color: #000000; padding: 0px; height: 29px; line-height: 29px; width: 98px; border: none;}
  5. .progress{height: 30px; position: relative; display: none;}
  6. .schedule{float: right;}
  7. .totalProgress{height: 11px; background-color: #F0F0F0; border-radius: 11px;}
  8. .complete{width: 0%; height: 11px; position: absolute; left: 0px; top: 14px; background-color: #03C501; border-radius: 11px;}
  9. </style>
  10. <div class="plusForm photo">
  11. <div>
  12. <div class="title">Upload video</div>
  13. <div class="close"><a href="javascript:;"><img src="<%=public_path%>/img/close-btn.png" alt=""/></a></div>
  14. </div>
  15. <div class="content">
  16. <div>Video cover <label>(JPG & PNG only, size less than 3M. Image short-edit must be longer than 380px.)</label></div>
  17. <input class="uploadFile" id="uploadFile" disabled="disabled" style="background: none;" placeholder=""/>
  18. <div class="fileUpload btn btn-primary">
  19. <div id="filePicker">Video cover</div>
  20. <input type="hidden" name="img" value="">
  21. </div>
  22. <div>Video <label>(MP4, MOV format allowed)</label></div>
  23. <input class="uploadFile" id="uploadVideo" disabled="disabled" style="background: none;" placeholder="">
  24. <div class="fileUpload btn btn-primary">
  25. <div id="fileVideo">Browse video</div>
  26. <input type="hidden" name="video" value="">
  27. </div>
  28. <!--<div>Video description <label> (28 character limited)</label></div>-->
  29. <!--<input type="text" name="title" class="dec" maxlength="28">-->
  30. <div class="progress" style="margin-bottom: 5px;">
  31. <div>Upload progress<span class="schedule">0%</span></div>
  32. <div class="totalProgress"></div>
  33. <div class="complete"></div>
  34. </div>
  35. <button class="Submit cursor">Upload</button>
  36. </div>
  37. </div>
  38. <script>
  39. $(function(){
  40. var anchor_video_key = '';
  41. var server = '';
  42. //创建文件上传
  43. var uploader_video = WebUploader.create({
  44. auto: true,
  45. fileSingleSizeLimit: 1024*1024*30,//视频最大可以上传30M
  46. swf: '<%=public_path%>' + '/js/webuploader/Uploader.swf',
  47. server: server,
  48. pick: '#fileVideo',
  49. resize: false,
  50. timeout: 30 * 60 * 1000,
  51. accept: {
  52. title: 'Video',
  53. extensions: 'mp4,mov',
  54. mimeTypes: 'video/mp4,video/quicktime'
  55. },
  56. compress: null
  57. });
  58. /**
  59. * 上传前设置参数
  60. */
  61. uploader_video.on( 'startUpload', function() {
  62. var serverType = <%=serverType%>;
  63. anchor_video_key = getCodeKey();
  64. server = '<%=url%>/AnchorVideoUpload/AnchorVideoServlet.htm?siteID=8&anchorID=<%=userInfo.id%>&agentID=<%=anchorInfo.agency_id%>&anchor_video_key='+anchor_video_key+'&video_type=0&serverType='+serverType;
  65. uploader_video.options.server = server;
  66. });
  67. // 文件上传中
  68. var uploadVideo = 0;//防止重复提示
  69. var loadVideo = '';
  70. uploader_video.on( 'uploadProgress', function( file, percentage ) {
  71. $('.progress').show();
  72. parent.layer.iframeAuto(index);
  73. $('.schedule').text(parseInt(percentage*100)+'%');
  74. $('.complete').css('width',parseInt(percentage*100)+'%');
  75. if (!uploadVideo) {
  76. loadVideo = layer.load(2);
  77. }
  78. uploadVideo = 1//等于1表示上传动作已经开启
  79. });
  80. //文件上传成功
  81. uploader_video.on( 'uploadSuccess', function( file, response) {
  82. uploader_video.removeFile( file );//从队列中移除上传的文件,以便可以重复上传
  83. uploadVideo =0;//重置开关
  84. layer.close(loadVideo);
  85. $('.progress').hide();
  86. if(response._raw){
  87. $('#uploadVideo').val(file.name);
  88. $('input[name="video"]').val(anchor_video_key);
  89. }else{
  90. myParentAlert("Failed to upload. Please try again.");
  91. }
  92. });
  93. //文件上传失败
  94. uploader_video.on( 'uploadError', function( file , reason) {
  95. uploadVideo = 0;//重置开关
  96. layer.close(loadVideo);
  97. $('.progress').hide();
  98. if(reason == 'timeout'){
  99. myParentAlert("Could not upload video. The process has timed out.");
  100. }else{
  101. myParentAlert("Failed to upload. Please try again.");
  102. }
  103. });
  104. //文件错误提示
  105. uploader_video.on("error", function (type) {
  106. $('.progress').hide();
  107. if(type == "Q_TYPE_DENIED"){
  108. myParentAlert("Only MP4, MOV format allowed for video file.");
  109. }
  110. if(type == "F_EXCEED_SIZE"){
  111. myParentAlert("The file size can not larger than 30M.");
  112. }
  113. });
  114. //创建图片上传
  115. var uploader = WebUploader.create({
  116. auto: true,
  117. fileSingleSizeLimit: 1024*1024*3,//最大只能上传3M
  118. swf: '<%=public_path%>' + '/js/webuploader/Uploader.swf',
  119. server: '<%=server_host%>/api/?act=uploadAlbumVideoCover',
  120. pick: '#filePicker',
  121. accept: {
  122. title: 'Images',
  123. extensions: 'jpg,jpeg,png',
  124. mimeTypes: 'image/jpg,image/jpeg,image/png'
  125. },
  126. compress: null
  127. });
  128. // 图片上传中
  129. var uploadProgress = 0;//防止重复提示
  130. var load = '';
  131. uploader.on( 'uploadProgress', function( file, percentage ) {
  132. $('.progress').show();
  133. parent.layer.iframeAuto(index);
  134. $('.schedule').text(parseInt(percentage*100)+'%');
  135. $('.complete').css('width',parseInt(percentage*100)+'%');
  136. if (!uploadProgress) {
  137. load = layer.load(2);
  138. }
  139. uploadProgress = 1//等于1表示不上传动作已经开启
  140. });
  141. //图片上传成功
  142. uploader.on( 'uploadSuccess', function( file, response) {
  143. $('.progress').hide();
  144. if(response.errno == 13){
  145. myParentAlert("JPG & PNG only, size less than 3M. Image short-edit must be longer than 380px.");
  146. }
  147. if(response.errno == 14){
  148. myParentAlert("The photo resolution can not be larger than 3600 * 3600.");
  149. }
  150. uploader.removeFile( file );//从队列中移除上传的文件,以便可以重复上传
  151. if(response.errno == 0){
  152. $('#uploadFile').val(file.name);
  153. $('input[name="img"]').val(response.data.url);
  154. }
  155. uploadProgress =0;//重置开关
  156. layer.close(load);
  157. });
  158. //图片上传失败
  159. uploader.on( 'uploadError', function( file ) {
  160. $('.progress').hide();
  161. uploadProgress = 0;//重置开关
  162. layer.close(load);
  163. myParentAlert("Failed to upload. Please try again.");
  164. });
  165. //错误提示
  166. uploader.on("error", function (type) {
  167. $('.progress').hide();
  168. if(type == "Q_TYPE_DENIED"){
  169. myParentAlert("Only JPG and PNG format allowed for video cover. File size must be 3M or less.");
  170. }
  171. if(type == "F_EXCEED_SIZE"){
  172. myParentAlert("Incorrect format. Only JPG and PNG format allowed. File size must be 3M or less.");
  173. }
  174. });
  175. var index = parent.layer.getFrameIndex(window.name);
  176. parent.layer.iframeAuto(index);
  177. $('.close').click(function(){
  178. parent.layer.close(index);
  179. })
  180. var change_status = 0;//防止多次点击
  181. $('.Submit').click(function(){
  182. if(change_status){
  183. return false;
  184. }
  185. change_status = 1;
  186. // var title = $('input[name="title"]').val();
  187. var img = $('input[name="img"]').val();
  188. var video = $('input[name="video"]').val();
  189. if(!img){
  190. myParentAlert('Please select a video cover image.');
  191. change_status = 0;
  192. return false;
  193. }else if(!video){
  194. myParentAlert('Please select an valid video file.');
  195. change_status = 0;
  196. return false;
  197. }
  198. // if(!title){
  199. // myParentAlert('Please enter video description.');
  200. // change_status = 0;
  201. // return false;
  202. // }
  203. $.post('/broadcast/albumLayer/addVideo', {img:img, video:video}, function(data){
  204. if(data.errno == 0){
  205. Cookies.set('add_success_video', {status:1});
  206. parent.layer.close(index);
  207. parent.layer.msg('Submit successfully. Auditing soon.');
  208. }else{
  209. myParentAlert('Failed to submit. Please try again.');
  210. change_status = 0;
  211. }
  212. })
  213. })
  214. })
  215. </script>