用Ext js6连接电脑摄像头实现拍照和保存录像的例子
时间: 2023-05-24 09:03:01 浏览: 70
A:
以下是使用Ext JS 6连接电脑摄像头实现拍照和保存录像的示例代码:
1. 引入依赖库:
```
Ext.Loader.setConfig({
enabled: true,
disableCaching: false,
paths: {
'Ext.ux': 'http://cdn.sencha.com/ext/gpl/5.1.1/examples/ux'
}
});
Ext.require([
'Ext.window.Window',
'Ext.ux.IFrame',
'Ext.ux.LiveSearchGridPanel',
'Ext.ux.form.HtmlEditor.Video'
]);
```
2. 声明视频播放器:
```
xtype: 'panel',
title: '视频播放器',
frame: true,
width: 400,
height: 300,
layout: 'fit',
items: {
xtype: 'ux-video',
url: 'http://cdn.sencha.com/ext/gpl/5.1.1/examples/videos/video.mp4',
posterUrl: 'http://cdn.sencha.com/ext/gpl/5.1.1/examples/videos/video-poster.jpg'
}
```
3. 声明摄像头:
```
var video = Ext.create('Ext.ux.Video', {
width: 800,
height: 600,
corsProxyUrl: 'http://robwu.nl/cors-anywhere.html',
enableControls: true,
listeners: {
initialize: function(video) {
var recorder = video.getRecorder();
var controls = Ext.create('Ext.container.Container', {
layout: 'hbox',
items: [{
xtype: 'button',
text: 'Start Recording',
handler: function() {
recorder.start();
}
}, {
xtype: 'button',
text: 'Pause Recording',
handler: function() {
recorder.pause();
}
}, {
xtype: 'button',
text: 'Resume Recording',
handler: function() {
recorder.resume();
}
}, {
xtype: 'button',
text: 'Stop Recording',
handler: function() {
recorder.stop();
}
}]
});
controls.render(video.getId() + '-ct');
}
}
});
Ext.create('Ext.window.Window', {
width: 800,
height: 600,
layout: 'fit',
items: video
}).show();
```
4. 显示摄像头,并添加保存录像和拍照的按钮:
```
var video = Ext.create('Ext.ux.Video', {
// ...
});
Ext.create('Ext.window.Window', {
width: 800,
height: 600,
layout: 'fit',
items: [video, {
xtype: 'toolbar',
dock: 'top',
items: [{
text: 'Save Recording',
handler: function() {
var blob = video.getRecorder().getBlob();
var url = URL.createObjectURL(blob);
Ext.create('Ext.window.Window', {
width: 400,
height: 400,
layout: 'fit',
items: {
xtype: 'ux-iframe',
src: 'saveRecording.php',
method: 'POST',
params: {
'video': {
blob: blob,
name: 'recording.mp4'
}
}
}
}).show();
}
}, {
text: 'Take Snapshot',
handler: function() {
video.snapshot(function(blob) {
var url = URL.createObjectURL(blob);
Ext.create('Ext.window.Window', {
width: 400,
height: 400,
layout: 'fit',
items: [{
xtype: 'image',
src: url
}]
}).show();
});
}
}]
}]
}).show();
```
注意:将“saveRecording.php”替换为服务器端脚本的路径和名称,并根据需要添加相关的参数。