Browse files

fixing various range/header issues, adding embedded test video

  • Loading branch information...
1 parent 310817d commit e15bb308a54705e74aaf1f6b644e370a8a479eca @benvanik committed Nov 23, 2011
Showing with 38 additions and 21 deletions.
  1. +33 −14 apps/chrome/src/test.html
  2. +5 −7 lib/content.js
View
47 apps/chrome/src/test.html
@@ -11,6 +11,8 @@
var deviceList;
var statusBox;
+ var infoBox;
+ var embeddedVideo;
var seekBar;
var isSeeking = false;
@@ -94,9 +96,9 @@
targetDevice.stop();
}
- function testRemote() {
+ function testRemote(embed) {
var content = 'http://wwwappskc.lonestar.edu/cgi/video/html5/test.m4v';
- play(content);
+ play(content, embed);
}
function waitUntilContentReady(contentId, callback) {
@@ -114,7 +116,7 @@
checkReady();
}
- function testContent(url) {
+ function testContent(url, embed) {
var source = {
content: url
};
@@ -128,35 +130,42 @@
waitUntilContentReady(contentId, function(info) {
// TODO: better presentation
infoBox.innerText = JSON.stringify(info);
- play(endpoint + '/content/' + contentId);
+ play(endpoint + '/content/' + contentId, embed);
});
});
}
- function testContentLocal() {
- testContent('file:///Users/noxa/test_videos/test.m4v');
+ function testContentLocal(embed) {
+ testContent('file:///Users/noxa/test_videos/test.m4v', embed);
}
- function testContentRemote() {
- testContent('http://wwwappskc.lonestar.edu/cgi/video/html5/test.m4v');
+ function testContentRemote(embed) {
+ testContent('http://wwwappskc.lonestar.edu/cgi/video/html5/test.m4v',
+ embed);
}
- function testContentFlv() {
- testContent('file:///Users/noxa/test_videos/test.flv');
+ function testContentFlv(embed) {
+ testContent('file:///Users/noxa/test_videos/test.flv', embed);
}
- function testContentWebM() {
- testContent('file:///Users/noxa/test_videos/test1.webm');
+ function testContentWebM(embed) {
+ testContent('file:///Users/noxa/test_videos/test1.webm', embed);
}
- function play(content) {
- targetDevice.play(content, 0);
+ function play(content, embed) {
+ if (embed) {
+ embeddedVideo.src = content;
+ embeddedVideo.play();
+ } else {
+ targetDevice.play(content, 0);
+ }
}
window.addEventListener('load', function() {
deviceList = document.getElementById('deviceList');
infoBox = document.getElementById('infoBox');
statusBox = document.getElementById('statusBox');
+ embeddedVideo = document.getElementById('embeddedVideo');
seekBar = document.getElementById('seekBar');
seekBar.addEventListener('mousedown', function() {
isSeeking = true;
@@ -202,5 +211,15 @@
<div id="infoBox">
[info]
</div>
+ <br/>
+ <br/>
+ <div>
+ <a href="javascript:testRemote(true);">test</a>&nbsp;
+ <a href="javascript:testContentLocal(true);">test/fs</a>&nbsp;
+ <a href="javascript:testContentRemote(true);">test/remote</a>&nbsp;
+ <a href="javascript:testContentFlv(true);">test/flv</a>&nbsp;
+ <a href="javascript:testContentWebM(true);">test/webm</a>&nbsp;
+ <video id="embeddedVideo"/>
+ </div>
</body>
</html>
View
12 lib/content.js
@@ -234,10 +234,8 @@ Content.prototype.offlineTranscode_ = function(callback) {
return;
}
- // ?
+ callback(null);
});
-
- callback(null);
};
var sourceUrl = url.parse(this.source.content);
@@ -321,9 +319,9 @@ Content.prototype.localFileGet = function(req, res, sourceUrl) {
var start = 0;
var end = stats.size;
if (req.headers['range']) {
- var range = req.headers['range'].match(/([0-9]+)-([0-9]+)/);
+ var range = req.headers['range'].match(/([0-9]+)-([0-9]+)?/);
start = parseInt(range[1]);
- end = parseInt(range[2]);
+ end = range[2] !== undefined ? parseInt(range[2]) : stats.size - 1;
headers['Content-Length'] = end - start + 1;
if (start == 0 && end == stats.size) {
res.writeHead(200, headers);
@@ -334,6 +332,7 @@ Content.prototype.localFileGet = function(req, res, sourceUrl) {
}
} else {
headers['Content-Length'] = stats.size;
+ headers['Content-Range'] = 'bytes 0-' + stats.size + '/' + stats.size;
res.writeHead(200, headers);
}
fs.createReadStream(filename, {
@@ -371,8 +370,7 @@ Content.prototype.remoteHttpGet = function(req, res, sourceUrl) {
} else {
util.puts('remote server returned bad content type: ' + contentType);
}
- var transcoder = new Transcoder(source, target);
- remoteHeaders['content-type'] = 'video/mp4';
+ remoteHeaders['content-type'] = target.mimeType;
res.writeHead(remoteRes.statusCode, remoteHeaders);

0 comments on commit e15bb30

Please sign in to comment.