Skip to content

Commit

Permalink
Bug 815791 - separate video view activity from video player app
Browse files Browse the repository at this point in the history
  • Loading branch information
David Flanagan committed Dec 28, 2012
1 parent b4f1deb commit de09697
Show file tree
Hide file tree
Showing 5 changed files with 376 additions and 83 deletions.
84 changes: 11 additions & 73 deletions apps/video/js/video.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var ids = ['player', 'thumbnails', 'overlay', 'overlay-title',
'overlay-text', 'videoControls', 'videoFrame', 'videoBar', 'overlay-text', 'videoControls', 'videoFrame', 'videoBar',
'close', 'play', 'playHead', 'timeSlider', 'elapsedTime', 'close', 'play', 'playHead', 'timeSlider', 'elapsedTime',
'video-title', 'duration-text', 'elapsed-text', 'bufferedTime', 'video-title', 'duration-text', 'elapsed-text', 'bufferedTime',
'slider-wrapper', 'throbber', 'delete-video-button', 'delete-confirmation-button']; 'slider-wrapper', 'throbber', 'delete-video-button',
'delete-confirmation-button'];


ids.forEach(function createElementRef(name) { ids.forEach(function createElementRef(name) {
dom[toCamelCase(name)] = document.getElementById(name); dom[toCamelCase(name)] = document.getElementById(name);
Expand Down Expand Up @@ -41,10 +42,6 @@ var THUMBNAIL_HEIGHT = 160;
// Enumerating the readyState for html5 video api // Enumerating the readyState for html5 video api
var HAVE_NOTHING = 0; var HAVE_NOTHING = 0;


var activityData; // From an activity call
var pendingActivity;
var appStarted = false;

var storageState; var storageState;
var currentOverlay; var currentOverlay;


Expand All @@ -65,9 +62,6 @@ function init() {
storageState = false; storageState = false;
updateDialog(); updateDialog();
createThumbnailList(); createThumbnailList();
if (activityData) {
startStream();
}
}; };


videodb.onscanstart = function() { videodb.onscanstart = function() {
Expand All @@ -88,9 +82,8 @@ function init() {
event.detail.forEach(videoDeleted); event.detail.forEach(videoDeleted);
}; };


dom.deleteConfirmationButton.addEventListener('click', deleteSelectedVideoFile, false); dom.deleteConfirmationButton.addEventListener('click',

deleteSelectedVideoFile, false);
appStarted = true;
} }


function videoAdded(videodata) { function videoAdded(videodata) {
Expand Down Expand Up @@ -153,11 +146,11 @@ function videoAdded(videodata) {
dom.thumbnails.addEventListener('contextmenu', function(evt) { dom.thumbnails.addEventListener('contextmenu', function(evt) {
var node = evt.target; var node = evt.target;
var found = false; var found = false;
while (!found && node) { while (!found && node) {
if (node.dataset.name) { if (node.dataset.name) {
found = true; found = true;
selectedVideo = node.dataset.name; selectedVideo = node.dataset.name;
} else { } else {
node = node.parentNode; node = node.parentNode;
} }
} }
Expand Down Expand Up @@ -208,11 +201,6 @@ function updateDialog() {
} }
} }


function startStream() {
showPlayer(activityData, true);
activityData = null;
}

function metaDataParser(videofile, callback, metadataError) { function metaDataParser(videofile, callback, metadataError) {


var previewPlayer = document.createElement('video'); var previewPlayer = document.createElement('video');
Expand Down Expand Up @@ -372,12 +360,6 @@ function setVideoPlaying(playing) {
} }
} }


function completeActivity(deleteVideo) {
pendingActivity.postResult({delete: deleteVideo});
pendingActivity = null;
dom.thumbnails.classList.remove('hidden');
}

function playerMousedown(event) { function playerMousedown(event) {
// If we interact with the controls before they fade away, // If we interact with the controls before they fade away,
// cancel the fade // cancel the fade
Expand Down Expand Up @@ -602,14 +584,9 @@ function playerEnded() {
clearTimeout(endedTimer); clearTimeout(endedTimer);
endedTimer = null; endedTimer = null;
} }
if (pendingActivity) {
pause(); dom.player.currentTime = 0;
dom.player.currentTime = 0; document.mozCancelFullScreen();
setControlsVisibility(true);
} else {
dom.player.currentTime = 0;
document.mozCancelFullScreen();
}
} }


function play() { function play() {
Expand Down Expand Up @@ -762,33 +739,6 @@ function formatDuration(duration) {
return ''; return '';
} }


function actHandle(activity) {
var data = activity.source.data;
var title = 'extras' in data ? (data.extras.title || '') : '';
switch (activity.source.name) {
case 'open':
// Activities are required to specify whether they are inline in the manifest
// so we know we are inline, dont bother showing thumbnails
dom.thumbnails.classList.add('hidden');
pendingActivity = activity;
var filename = data.src.replace(/^ds\:videos:\/\//, '');
activityData = {
fromMediaDB: false,
name: filename,
title: title
};
break;
case 'view':
activityData = {
url: data.url,
title: title
};
break;
}
if (appStarted) {
startStream();
}
}


// The mozRequestFullScreen can fail silently, so we keep asking // The mozRequestFullScreen can fail silently, so we keep asking
// for full screen until we detect that it happens, We limit the // for full screen until we detect that it happens, We limit the
Expand All @@ -802,20 +752,12 @@ function requestFullScreen(callback) {
if (++requests > MAX_FULLSCREEN_REQUESTS) { if (++requests > MAX_FULLSCREEN_REQUESTS) {
window.clearInterval(fullscreenTimer); window.clearInterval(fullscreenTimer);
fullscreenTimer = null; fullscreenTimer = null;
if (pendingActivity) {
pendingActivity.postError('Could not play video');
pendingActivity = null;
}
return; return;
} }
dom.videoFrame.mozRequestFullScreen(); dom.videoFrame.mozRequestFullScreen();
}, 500); }, 500);
} }


if (window.navigator.mozSetMessageHandler) {
window.navigator.mozSetMessageHandler('activity', actHandle);
}

// When we exit fullscreen mode, stop playing the video. // When we exit fullscreen mode, stop playing the video.
// This happens automatically when the user uses the back button (because // This happens automatically when the user uses the back button (because
// back is Escape, which is also the "leave fullscreen mode" command). // back is Escape, which is also the "leave fullscreen mode" command).
Expand All @@ -824,11 +766,7 @@ if (window.navigator.mozSetMessageHandler) {
document.addEventListener('mozfullscreenchange', function() { document.addEventListener('mozfullscreenchange', function() {
// We have exited fullscreen // We have exited fullscreen
if (document.mozFullScreenElement === null) { if (document.mozFullScreenElement === null) {
if (pendingActivity) { hidePlayer();
completeActivity(false);
} else {
hidePlayer();
}
return; return;
} }


Expand Down
Loading

0 comments on commit de09697

Please sign in to comment.