summaryrefslogtreecommitdiffstats
path: root/assets/js/models/sample.js
blob: 61eb2afbd84c4a1dbf8416740485c31ff6bcdb0a (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
ClipPlay.Models.Sample = Backbone.Model.extend({
	defaults: {
		'url': '',
		'start': '',
		'stop': '',
		'duration': '',
		'key': '',
		'player': '',
		'iframe': '',
        'timeout' : ''
	},


	in_minutes_and_seconds: function(seconds) {
		var minutes = Math.floor(seconds / 60);
		seconds = Math.floor(seconds);
		var seconds = seconds - minutes * 60;
		
		if (seconds < 10) {
			seconds = '0' + seconds;
		}
		
		return {
			minutes: minutes,
			seconds: seconds
		};
	},
	
	start_in_minutes_and_seconds: function() {
		return this.in_minutes_and_seconds(this.get('start'));
	},
	
	stop_in_minutes_and_seconds: function() {
		return this.in_minutes_and_seconds(this.get('stop'));
	},
	
	
	play: function() {
        console.log('playing');
    //play then pause
        window.clearTimeout(this.get('timeout'));
        this.get('player').pause();
        this.get('player').seekTo(this.get('start'));
        this.get('player').play();
        var that = this;
        var length = this.get('stop') - this.get('start');
        console.log(length);
        this.set('timeout',setTimeout(function(){
          that.get('player').pause();
        }, length*1000 ));
	}
});