Skip to content

Commit

Permalink
check if codec is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
lejenome committed Dec 13, 2014
1 parent 11abf61 commit 81ead0b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
9 changes: 6 additions & 3 deletions data/youtube-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ var prefChangeHandler = function() {};
var FORMATS = {
"18": {
container: "mp4",
resolution: "360p"
resolution: "360p",
type: "video/mp4; codecs=\"avc1.42001E, mp4a.40.2\""
},
"22": {
container: "mp4",
resolution: "720p"
resolution: "720p",
type: "video/mp4; codecs=\"avc1.64001F, mp4a.40.2\""
},
"43": {
container: "webm",
resolution: "360p"
resolution: "360p",
type: "video/webm; codecs=\"vp8.0, vorbis\""
}
};
/*
Expand Down
18 changes: 14 additions & 4 deletions data/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var player, player_container;

function main() {
player = createNode("video");
changePlayer();
window.addEventListener("spfrequest", function() {
if (player)
Expand Down Expand Up @@ -37,7 +38,6 @@
player_container.innerHTML = "";
var player_opt = {
id: "video_player",
src: conf.url,
className: "video-js vjs-default-skin " + conf.className,
controls: true,
volume: OPTIONS.volume / 100
Expand All @@ -47,6 +47,10 @@
else
player_opt.autoplay = true;
player = createNode("video", player_opt);
player.appendChild(createNode("source", {
src: conf.url,
type: conf.type
}));
//videojs(player); //TODO: use video-js custom video player
player_container.appendChild(player);
} catch (e) {
Expand Down Expand Up @@ -99,14 +103,20 @@
info.split(",").forEach(function(f, i) {
var itag = f.match(/itag=([^&]*)/)[1];
var url = decodeURIComponent(f.match(/url=([^&]*)/)[1]);
if (FORMATS[itag])
formats[itag] = url;
var type = decodeURIComponent(f.match(/type=([^&]*)/)[1]);
type = type.replace("+", " ", "g");
if (player.canPlayType(type) === "probably")
formats[itag] = {
url: url,
type: type
};
});
if (Object.keys(FORMATS).length < 1)
return Promise.reject();
for (var i = 0; i < PREF_FORMATS.length; i++)
if (formats[PREF_FORMATS[i]]) {
conf.url = formats[PREF_FORMATS[i]];
conf.url = formats[PREF_FORMATS[i]].url;
conf.type = formats[PREF_FORMATS[i]].type;
resolve(conf);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Moez Bouhlel <[email protected]> (http://lejenome.github.io/)",
"homepage": "https://github.com/lejenome/youtube-html5-player",
"license": "MPL 2.0",
"version": "0.1.5",
"version": "0.1.6",
"preferences": [
{
"name": "preferredCodec",
Expand Down
Binary file modified youtube-video-player.xpi
Binary file not shown.

0 comments on commit 81ead0b

Please sign in to comment.