This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
115 lines (89 loc) · 3.65 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
let video = document.querySelector('video');
function base64_to_buffer(i) {
let bin = window.atob(i)
let len = bin.length;
let bytes = new Uint8Array(len)
for (let i = 0; i < len; i++) {
bytes[i] = bin.charCodeAt(i)
}
return bytes.buffer
}
let ws = new WebSocket("ws:127.0.0.1:3012")
ws.onopen = () => {
ws.send("Here's some text that the server is urgently awaiting!");
};
ws.onmessage = (message) => {
console.log(message)
let blob = message.data
blob.type = "text/plain"
console.log(blob)
var reader = new FileReader();
reader.onload = function() {
video.src = "data:video/mp4;base64," + message.data
}
reader.readAsText(message);
}
// let video =
// var video = document.querySelector('video');
// var assetURL = 'video.mp4';
// // Need to be specific for Blink regarding codecs
// // ./mp4info frag_bunny.mp4 | grep Codec
// var mimeCodec = 'video/mp4';
// if ('MediaSource' in window && MediaSource.isTypeSupported(mimeCodec)) {
// var mediaSource = new MediaSource();
// //console.log(mediaSource.readyState); // closed
// video.src = URL.createObjectURL(mediaSource);
// mediaSource.addEventListener('sourceopen', sourceOpen);
// } else {
// console.error('Unsupported MIME type or codec: ', mimeCodec);
// }
// function sourceOpen (_) {
// //console.log(this.readyState); // open
// var mediaSource = this;
// var fileToLoad = this.files[0];
// var fileReader = new FileReader();
// fileReader.onload = function(fileLoadedEvent){
// var textFromFileLoaded = fileLoadedEvent.target.result
// sourceBuffer.appendBuffer(textFromFileLoaded);
// };
// fileReader.readAsText(fileToLoad, 'base64');
// sourceBuffer.addEventListener('updateend', function (_) {
// mediaSource.endOfStream();
// video.play();
// });
// sourceBuffer.appendBuffer(base64toBuffer());
// });
// };
// function base64toBuffer(base64) {
// var binary_string = window.atob(base64);
// var len = binary_string.length;
// var bytes = new Uint8Array( len );
// for (var i = 0; i < len; i++) {
// bytes[i] = binary_string.charCodeAt(i);
// }
// return bytes.buffer;
// }
// // let open = (_) => {
// // let mediaSource = this
// // let sourceBuffer = mediaSource.addSourceBuffer('video/mp4; base64')
// // sourceBuffer.addEventListener('updateend', function (_) {
// // mediaSource.endOfStream();
// // video.play();
// // //console.log(mediaSource.readyState); // ended
// // });
// // let control = document.getElementById('file');
// // control.addEventListener('change', function(event) {
// // var fileToLoad = this.files[0];
// // var fileReader = new FileReader();
// // fileReader.onload = function(fileLoadedEvent){
// // var textFromFileLoaded = fileLoadedEvent.target.result
// // sourceBuffer.appendBuffer(textFromFileLoaded);
// // };
// // fileReader.readAsText(fileToLoad, 'base64');
// // }, false);
// // }
// // let mediaSource = new MediaSource();
// // let video = document.querySelector('video')
// // //console.log(mediaSource.readyState); // closed
// // video.src = URL.createObjectURL(mediaSource);
// // mediaSource.addEventListener('sourceopen', open);