| author | hamidouk |
| Tue, 14 Feb 2012 17:14:57 +0100 | |
| branch | popcorn-port |
| changeset 809 | 1997dae651c6 |
| parent 758 | 7fdb2d92da58 |
| 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 ); |
|
758
7fdb2d92da58
trigger the seeked signal after seeking because due to a bug in jwplayer, it's
hamidouk
parents:
751
diff
changeset
|
29 |
this._Popcorn.currentTime( parseFloat(offsettime) ); |
|
7fdb2d92da58
trigger the seeked signal after seeking because due to a bug in jwplayer, it's
hamidouk
parents:
751
diff
changeset
|
30 |
|
|
7fdb2d92da58
trigger the seeked signal after seeking because due to a bug in jwplayer, it's
hamidouk
parents:
751
diff
changeset
|
31 |
/* we have to trigger this signal manually because of a |
|
7fdb2d92da58
trigger the seeked signal after seeking because due to a bug in jwplayer, it's
hamidouk
parents:
751
diff
changeset
|
32 |
bug in the jwplayer */ |
|
7fdb2d92da58
trigger the seeked signal after seeking because due to a bug in jwplayer, it's
hamidouk
parents:
751
diff
changeset
|
33 |
this._Popcorn.trigger("seeked", parseFloat(offsettime)); |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
34 |
} |
| 649 | 35 |
} 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
|
36 |
// annotation |
| 653 | 37 |
var annotationId = pageoffset.substring( 3 ); |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
38 |
// 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
|
39 |
// of possible race conditions |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
40 |
this._serializer.sync(IriSP.wrap(this, function() { |
| 587 | 41 |
this.lookupAnnotation.call(this, annotationId); |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
42 |
})); |
|
809
1997dae651c6
added some code to handle embedding in an iframe and mediafragment.
hamidouk
parents:
758
diff
changeset
|
43 |
} |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
44 |
} |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
45 |
}; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
46 |
|
| 749 | 47 |
/** handler for the seeked signal. It may have or may have not an argument. |
48 |
@param time if not undefined, the time we're seeking to |
|
49 |
*/ |
|
50 |
IriSP.MediaFragment.prototype.updateTime = function(time) { |
|
|
466
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
51 |
if (this.mutex === true) { |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
52 |
return; |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
53 |
} |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
54 |
|
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
55 |
var history = window.history; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
56 |
if ( !history.pushState ) { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
57 |
return false; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
58 |
} |
|
751
5cea0b550154
check if the seeked signal handler receives the seek destination argument.
hamidouk
parents:
749
diff
changeset
|
59 |
|
|
5cea0b550154
check if the seeked signal handler receives the seek destination argument.
hamidouk
parents:
749
diff
changeset
|
60 |
if (IriSP.null_or_undefined(time) || typeof(time) != "number") { |
| 749 | 61 |
var ntime = this._Popcorn.currentTime().toFixed(2) |
62 |
} else { |
|
63 |
var ntime = time.toFixed(2); |
|
64 |
} |
|
|
809
1997dae651c6
added some code to handle embedding in an iframe and mediafragment.
hamidouk
parents:
758
diff
changeset
|
65 |
|
|
1997dae651c6
added some code to handle embedding in an iframe and mediafragment.
hamidouk
parents:
758
diff
changeset
|
66 |
// used to relay the new hash to the embedder |
|
1997dae651c6
added some code to handle embedding in an iframe and mediafragment.
hamidouk
parents:
758
diff
changeset
|
67 |
this._Popcorn.trigger("IriSP.Mediafragment.hashchange", "#t=" + ntime); |
| 749 | 68 |
|
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
69 |
splitArr = window.location.href.split( "#" ) |
| 749 | 70 |
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
|
71 |
}; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
72 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
73 |
|
| 587 | 74 |
IriSP.MediaFragment.prototype.updateAnnotation = function(annotationId) { |
|
466
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
75 |
var _this = this; |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
76 |
this.mutex = true; |
|
d54cf60bb842
annotation requests and timecode request now both work.
hamidouk
parents:
462
diff
changeset
|
77 |
|
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
78 |
var history = window.history; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
79 |
if ( !history.pushState ) { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
80 |
return false; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
81 |
} |
|
809
1997dae651c6
added some code to handle embedding in an iframe and mediafragment.
hamidouk
parents:
758
diff
changeset
|
82 |
|
|
1997dae651c6
added some code to handle embedding in an iframe and mediafragment.
hamidouk
parents:
758
diff
changeset
|
83 |
|
|
1997dae651c6
added some code to handle embedding in an iframe and mediafragment.
hamidouk
parents:
758
diff
changeset
|
84 |
// used to relay the new hash to the embedder |
|
1997dae651c6
added some code to handle embedding in an iframe and mediafragment.
hamidouk
parents:
758
diff
changeset
|
85 |
this._Popcorn.trigger("IriSP.Mediafragment.hashchange", "#id=" + annotationId); |
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
86 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
87 |
splitArr = window.location.href.split( "#" ) |
| 649 | 88 |
history.replaceState( {}, "", splitArr[0] + "#id=" + annotationId); |
|
809
1997dae651c6
added some code to handle embedding in an iframe and mediafragment.
hamidouk
parents:
758
diff
changeset
|
89 |
|
|
1997dae651c6
added some code to handle embedding in an iframe and mediafragment.
hamidouk
parents:
758
diff
changeset
|
90 |
|
| 749 | 91 |
// 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
|
92 |
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
|
93 |
}; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
94 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
95 |
// lookup and seek to the beginning of an annotation |
| 587 | 96 |
IriSP.MediaFragment.prototype.lookupAnnotation = function(annotationId) { |
97 |
var _this = this; |
|
98 |
this.mutex = true; |
|
99 |
||
|
462
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
100 |
var annotation = undefined; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
101 |
var annotations = this._serializer._data.annotations; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
102 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
103 |
var i; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
104 |
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
|
105 |
if (annotations[i].id === annotationId) { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
106 |
annotation = annotations[i]; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
107 |
break; |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
108 |
} |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
109 |
} |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
110 |
|
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
111 |
if (typeof(annotation) !== "undefined") { |
|
3583ef3b208b
added a modules dir to the build. moved mediafragment.js module inside it.
hamidouk
parents:
diff
changeset
|
112 |
this._Popcorn.currentTime(annotation.begin / 1000); |
|
758
7fdb2d92da58
trigger the seeked signal after seeking because due to a bug in jwplayer, it's
hamidouk
parents:
751
diff
changeset
|
113 |
|
|
7fdb2d92da58
trigger the seeked signal after seeking because due to a bug in jwplayer, it's
hamidouk
parents:
751
diff
changeset
|
114 |
/* we have to trigger this signal manually because of a |
|
7fdb2d92da58
trigger the seeked signal after seeking because due to a bug in jwplayer, it's
hamidouk
parents:
751
diff
changeset
|
115 |
bug in the jwplayer */ |
|
7fdb2d92da58
trigger the seeked signal after seeking because due to a bug in jwplayer, it's
hamidouk
parents:
751
diff
changeset
|
116 |
this._Popcorn.trigger("seeked", annotation.begin / 1000); |
|
647
2984fbbcbe35
send a signal when loading an annotation from hashtag.
hamidouk
parents:
587
diff
changeset
|
117 |
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
|
118 |
} |
| 587 | 119 |
|
120 |
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
|
121 |
}; |