summaryrefslogtreecommitdiffstats
path: root/assets/js/views/sample.js
blob: 7aab111a625646171c9f2c85f01f17abeddb43a5 (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
ClipPlay.Views.Sample = Marionette.ItemView.extend({
	template: '#sample-view-template',

	onRender: function() {
		this.initialize_player();
		this.initialize_clip_lines();
	},


	initialize_player: function() {
		var that = this;
		$.embedly.oembed(this.model.get('url')).done(function(results){
			var BASE_IFRAME = "http://cdn.embedly.com/widgets/media.html";
			var data = results[0];
			var f= data.html;
			var src = encodeURIComponent($(f)[0].src);
			var schema = data.provider_name.toLowerCase();
			var iframe_src= BASE_IFRAME +"?schema="+schema+"&type=text%2Fhtml&html="+src;
            console.log(iframe_src);
			var iframe = $('<iframe/>', {
				src: iframe_src
			});
            console.log(iframe[0]);
			$('#video').append(iframe[0]);
			var player = new OP.Player(iframe[0]);
			that.model.set('player', player);
			that.model.set('iframe', iframe);

			// Trying to get the duration but this returns 0 for some reason
			// on the YouTube video I'm testing with
			player.getDuration(function(value) {
				that.model.set('duration', value);
			});
		});
	},

	initialize_clip_lines: function() {
		this.start_clip_line = new ClipPlay.Views.ClipLine({
			el: this.$('.js-start-position'),
			model: this.model
		});

		this.end_clip_line = new ClipPlay.Views.ClipLine({
			el: this.$('.js-end-position'),
			model: this.model
		});
	}
});