| author | hamidouk |
| Tue, 31 Jan 2012 15:32:35 +0100 | |
| branch | popcorn-port |
| changeset 750 | a1a3d09de1f4 |
| parent 749 | e9ee52225395 |
| child 751 | 5cea0b550154 |
| permissions | -rw-r--r-- |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
1 |
/* mediafragment module */ |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
2 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
3 |
IriSP.MediaFragment = function(Popcorn, config, Serializer) { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
4 |
IriSP.Module.call(this, Popcorn, config, Serializer); |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
5 |
|
|
466
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
6 |
this.mutex = false; /* a mutex because we access the url from two different functions */ |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
7 |
|
| 587 | 8 |
this._Popcorn.listen( "loadedmetadata", IriSP.wrap(this,this.advanceTime)); |
9 |
this._Popcorn.listen( "pause", IriSP.wrap(this,this.updateTime)); |
|
10 |
this._Popcorn.listen( "seeked", IriSP.wrap(this,this.updateTime)); |
|
11 |
this._Popcorn.listen( "IriSP.PolemicTweet.click", IriSP.wrap(this,this.updateAnnotation)); |
|
12 |
this._Popcorn.listen( "IriSP.SegmentsWidget.click", IriSP.wrap(this,this.updateAnnotation)); |
|
13 |
|
|
14 |
window.onhashchange = IriSP.wrap(this, this.advanceTime); |
|
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
15 |
}; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
16 |
|
| 587 | 17 |
IriSP.MediaFragment.prototype = new IriSP.Module(); |
18 |
||
19 |
IriSP.MediaFragment.prototype.advanceTime = function() { |
|
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
20 |
var url = window.location.href; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
21 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
22 |
if ( url.split( "#" )[ 1 ] != null ) { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
23 |
pageoffset = url.split( "#" )[1]; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
24 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
25 |
if ( pageoffset.substring(0, 2) === "t=") { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
26 |
// timecode |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
27 |
if ( pageoffset.substring( 2 ) != null ) { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
28 |
var offsettime = pageoffset.substring( 2 ); |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
29 |
this._Popcorn.currentTime( parseFloat( offsettime ) ); |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
30 |
} |
| 649 | 31 |
} else if ( pageoffset.substring(0, 3) === "id=") { |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
32 |
// annotation |
| 653 | 33 |
var annotationId = pageoffset.substring( 3 ); |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
34 |
// there's no better way than that because |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
35 |
// of possible race conditions |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
36 |
this._serializer.sync(IriSP.wrap(this, function() { |
| 587 | 37 |
this.lookupAnnotation.call(this, annotationId); |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
38 |
})); |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
39 |
} |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
40 |
} |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
41 |
}; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
42 |
|
| 749 | 43 |
/** handler for the seeked signal. It may have or may have not an argument. |
44 |
@param time if not undefined, the time we're seeking to |
|
45 |
*/ |
|
46 |
IriSP.MediaFragment.prototype.updateTime = function(time) { |
|
|
466
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
47 |
if (this.mutex === true) { |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
48 |
return; |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
49 |
} |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
50 |
|
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
51 |
var history = window.history; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
52 |
if ( !history.pushState ) { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
53 |
return false; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
54 |
} |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
55 |
|
| 749 | 56 |
|
57 |
if (IriSP.null_or_undefined(time)) { |
|
58 |
var ntime = this._Popcorn.currentTime().toFixed(2) |
|
59 |
} else { |
|
60 |
var ntime = time.toFixed(2); |
|
61 |
} |
|
62 |
|
|
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
63 |
splitArr = window.location.href.split( "#" ) |
| 749 | 64 |
history.replaceState( {}, "", splitArr[0] + "#t=" + ntime ); |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
65 |
}; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
66 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
67 |
|
| 587 | 68 |
IriSP.MediaFragment.prototype.updateAnnotation = function(annotationId) { |
|
466
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
69 |
var _this = this; |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
70 |
this.mutex = true; |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
71 |
|
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
72 |
var history = window.history; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
73 |
if ( !history.pushState ) { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
74 |
return false; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
75 |
} |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
76 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
77 |
splitArr = window.location.href.split( "#" ) |
| 649 | 78 |
history.replaceState( {}, "", splitArr[0] + "#id=" + annotationId); |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
79 |
|
| 749 | 80 |
// reset the mutex afterwards to prevent the module from reacting to his own changes. |
|
466
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
81 |
window.setTimeout(function() { _this.mutex = false }, 50); |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
82 |
}; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
83 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
84 |
// lookup and seek to the beginning of an annotation |
| 587 | 85 |
IriSP.MediaFragment.prototype.lookupAnnotation = function(annotationId) { |
86 |
var _this = this; |
|
87 |
this.mutex = true; |
|
88 |
||
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
89 |
var annotation = undefined; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
90 |
var annotations = this._serializer._data.annotations; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
91 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
92 |
var i; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
93 |
for (i = 0; i < annotations.length; i++) { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
94 |
if (annotations[i].id === annotationId) { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
95 |
annotation = annotations[i]; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
96 |
break; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
97 |
} |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
98 |
} |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
99 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
100 |
if (typeof(annotation) !== "undefined") { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
101 |
this._Popcorn.currentTime(annotation.begin / 1000); |
|
647
2984fbbcbe35
send a signal when loading an annotation from hashtag.
hamidouk
parents:
587
diff
changeset
|
102 |
this._Popcorn.trigger("IriSP.Mediafragment.showAnnotation", annotationId); |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
103 |
} |
| 587 | 104 |
|
105 |
window.setTimeout(function() { _this.mutex = false }, 50); |
|
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
106 |
}; |