1- import { UIBreak , UIButton , UIInteger , UIPanel , UIProgress , UIRow , UIText } from './libs/ui.js' ;
1+ import { UIBreak , UIButton , UIInteger , UIPanel , UIRow , UIText } from './libs/ui.js' ;
22
33import { APP } from './libs/app.js' ;
44
55function SidebarProjectVideo ( editor ) {
66
77 const strings = editor . strings ;
88
9- const save = editor . utils . save ;
10-
119 const container = new UIPanel ( ) ;
1210 container . setId ( 'render' ) ;
1311
@@ -48,27 +46,41 @@ function SidebarProjectVideo( editor ) {
4846
4947 // Render
5048
51- const progress = new UIProgress ( 0 ) ;
52- progress . setDisplay ( 'none' ) ;
53- progress . setWidth ( '170px' ) ;
54- progress . setMarginLeft ( '90px' ) ;
55- container . add ( progress ) ;
56-
5749 const renderButton = new UIButton ( strings . getKey ( 'sidebar/project/render' ) ) ;
5850 renderButton . setWidth ( '170px' ) ;
5951 renderButton . setMarginLeft ( '90px' ) ;
6052 renderButton . onClick ( async ( ) => {
6153
62- renderButton . setDisplay ( 'none' ) ;
63- progress . setDisplay ( '' ) ;
64- progress . setValue ( 0 ) ;
65-
6654 const player = new APP . Player ( ) ;
6755 player . load ( editor . toJSON ( ) ) ;
6856 player . setPixelRatio ( 1 ) ;
6957 player . setSize ( videoWidth . getValue ( ) , videoHeight . getValue ( ) ) ;
7058
71- const canvas = player . dom . firstElementChild ;
59+ //
60+
61+ const width = videoWidth . getValue ( ) / window . devicePixelRatio ;
62+ const height = videoHeight . getValue ( ) / window . devicePixelRatio ;
63+
64+ const canvas = player . canvas ;
65+ canvas . style . width = width + 'px' ;
66+ canvas . style . height = height + 'px' ;
67+
68+ const left = ( screen . width / 2 ) - ( width / 2 ) ;
69+ const top = ( screen . height / 2 ) - ( height / 2 ) ;
70+
71+ const output = window . open ( '' , '_blank' , `location=no,left=${ left } ,top=${ top } ,width=${ width } ,height=${ height } ` ) ;
72+ output . document . body . style . background = '#000' ;
73+ output . document . body . style . margin = '0px' ;
74+ output . document . body . style . overflow = 'hidden' ;
75+ output . document . body . appendChild ( canvas ) ;
76+
77+ const progress = document . createElement ( 'progress' ) ;
78+ progress . style . position = 'absolute' ;
79+ progress . style . top = '10px' ;
80+ progress . style . left = ( ( width - 170 ) / 2 ) + 'px' ;
81+ progress . style . width = '170px' ;
82+ progress . value = 0 ;
83+ output . document . body . appendChild ( progress ) ;
7284
7385 //
7486
@@ -79,7 +91,7 @@ function SidebarProjectVideo( editor ) {
7991
8092 ffmpeg . setProgress ( ( { ratio } ) => {
8193
82- progress . setValue ( ( ratio * 0.5 ) + 0.5 ) ;
94+ progress . value = ( ratio * 0.5 ) + 0.5 ;
8395
8496 } ) ;
8597
@@ -97,7 +109,7 @@ function SidebarProjectVideo( editor ) {
97109 ffmpeg . FS ( 'writeFile' , `tmp.${ num } .png` , await fetchFile ( canvas . toDataURL ( ) ) ) ;
98110 currentTime += 1 / fps ;
99111
100- progress . setValue ( ( i / frames ) * 0.5 ) ;
112+ progress . value = ( i / frames ) * 0.5 ;
101113
102114 }
103115
@@ -112,12 +124,18 @@ function SidebarProjectVideo( editor ) {
112124
113125 }
114126
115- save ( new Blob ( [ data . buffer ] , { type : 'video/mp4' } ) , 'out.mp4' ) ;
127+ output . document . body . removeChild ( canvas ) ;
128+ output . document . body . removeChild ( progress ) ;
116129
117- player . dispose ( ) ;
130+ const video = document . createElement ( 'video' ) ;
131+ video . width = width ;
132+ video . height = height ;
133+ video . controls = true ;
134+ video . loop = true ;
135+ video . src = URL . createObjectURL ( new Blob ( [ data . buffer ] , { type : 'video/mp4' } ) ) ;
136+ output . document . body . appendChild ( video ) ;
118137
119- renderButton . setDisplay ( '' ) ;
120- progress . setDisplay ( 'none' ) ;
138+ player . dispose ( ) ;
121139
122140 } ) ;
123141 container . add ( renderButton ) ;
0 commit comments