Welcome to mirror list, hosted at ThFree Co, Russian Federation.

viewer.js « js - github.com/nextcloud/files_videoplayer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 93a091e33d237e5a81128f180b47b9a98f88a5bf (plain)
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
var videoViewer = {
	UI : {
		playerTemplate : '<header><link href="'+OC.filePath('files_videojs-sublime', 'videojs', 'src')+'/video-js.css" rel="stylesheet"><script src="'+OC.filePath('files_videojs-sublime', 'videojs', 'src')+'/video.js"></script>' + '<script>' +
		'_V_.options.flash.swf = "'+OC.filePath('files_videojs-sublime', 'videojs', 'src')+'/video-js.swf"' +
		'</script>' + '</header><video id="my_video_1" class="video-js vjs-sublime-skin" controls preload="auto" width="100%" height="100%" poster="'+OC.filePath('files_videojs-sublime', '', 'img')+'/poster.png" data-setup="{}">' +
		'<source type="%type%" src="%src%" />' +
		'</video>',
		show : function () {
			// insert HTML
			$('<div id="videoplayer_overlay" style="display:none;"><div id="videoplayer_outer_container"><div id="videoplayer_container"><div id="videoplayer"><a class="box-close" id="box-close" href="#"></a></div></div></div></div>').appendTo('body');
			var playerView = videoViewer.UI.playerTemplate
								.replace(/%type%/g, videoViewer.mime)
								.replace(/%src%/g, videoViewer.location)
			;
			$(playerView).prependTo('#videoplayer');
			// add event to close icon
			$('#box-close').click(videoViewer.hidePlayer);
			// add event to overlay
			$("#videoplayer_overlay").on("click", function(e) {
				if (e.target != this) {
					return;
				} else {
					videoViewer.hidePlayer();
				}
			});
			// add event to ESC key
			$(document).keyup(function(e) {
			  if (e.keyCode === 27) {
			    videoViewer.hidePlayer();
			  }
			});
			// show elements
			$('#videoplayer_overlay').fadeIn('fast');
			// autoplay
			var vjsPlayer = videojs("my_video_1");
			vjsPlayer.play();
		},
		hide : function() {
			$('#videoplayer_overlay').fadeOut('fast', function() {
				$('#videoplayer_overlay').remove();
			});
		}
	},
	mime : null,
	file : null,
	location : null,
	player : null,
	mimeTypes : [
		'video/mp4',
		'video/webm',
		'video/x-flv',
		'video/ogg',
	],
	onView : function(file) {
		videoViewer.file = file;
		videoViewer.location = videoViewer.getMediaUrl(file);
		videoViewer.mime = FileActions.getCurrentMimeType();
		videoViewer.showPlayer();
	},
	showPlayer : function() {
		videoViewer.UI.show();
	},
	hidePlayer : function() {
		videoViewer.player = false;
		delete videoViewer.player;

		videoViewer.UI.hide();
	},
	getMediaUrl : function(file) {
		var dir = $('#dir').val();
		return fileDownloadPath(dir, file);
	},
	log : function(message){
		console.log(message);
	}
};

$(document).ready(function(){

	if (typeof FileActions !== 'undefined') {
		for (var i = 0; i < videoViewer.mimeTypes.length; ++i) {
			var mime = videoViewer.mimeTypes[i];
                        console.log(mime);
			FileActions.register(mime, 'View', OC.PERMISSION_READ, '', videoViewer.onView);
			FileActions.setDefault(mime, 'View');

		}
	}

});