src/js/players/player.allocine.js
author veltr
Thu, 10 May 2012 18:48:09 +0200
branchnew-model
changeset 887 6a04bd37da0a
parent 884 10233337f6da
child 919 972099304059
permissions -rw-r--r--
Corrected lib loading function so several instances of the Metadataplayer can be called
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     1
/* To wrap a player the develop should create a new class derived from
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     2
the IriSP.PopcornReplacement.player and defining the correct functions */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     3
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     4
/** allocine player wrapper */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     5
IriSP.PopcornReplacement.allocine = function(container, options) {
822
45083178c1d2 Corrections
veltr
parents: 819
diff changeset
     6
//    console.log("Calling allocine player");
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     7
    /* appel du parent pour initialiser les structures communes à tous les players */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     8
    IriSP.PopcornReplacement.player.call(this, container, options);   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     9
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    10
    var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    11
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    12
    /* Définition des fonctions de l'API -  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    13
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    14
    this.playerFns = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    15
        play : function() {
841
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    16
            return _this.apiCall("play");
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    17
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    18
        pause : function() {
841
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    19
            return _this.apiCall("pause");
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    20
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    21
        getPosition : function() {
841
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    22
            return _this.apiCall("getSeek","return") || 0;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    23
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    24
        seek : function(pos) {
841
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    25
            return _this.apiCall("seek",pos);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    26
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    27
        getMute : function() {
841
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    28
            return _this.apiCall("getMute","return");
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    29
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    30
        setMute : function(p) {
841
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    31
            return _this.apiCall("setMute", p);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    32
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    33
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    34
884
10233337f6da Refactoring tests
veltr
parents: 866
diff changeset
    35
    window.onReady = function() {
10233337f6da Refactoring tests
veltr
parents: 866
diff changeset
    36
        _this.ready();
10233337f6da Refactoring tests
veltr
parents: 866
diff changeset
    37
    };
10233337f6da Refactoring tests
veltr
parents: 866
diff changeset
    38
    window.onAllocineStateChange = function(_state) {
10233337f6da Refactoring tests
veltr
parents: 866
diff changeset
    39
        _this.stateHandler(_state)
10233337f6da Refactoring tests
veltr
parents: 866
diff changeset
    40
    }
10233337f6da Refactoring tests
veltr
parents: 866
diff changeset
    41
    window.onTime = function(_progress) {
10233337f6da Refactoring tests
veltr
parents: 866
diff changeset
    42
        _this.progressHandler(_progress)
10233337f6da Refactoring tests
veltr
parents: 866
diff changeset
    43
    };
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    44
    
842
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    45
    var _flashVars = {
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    46
        "streamFMS" : true,
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    47
        "adVast" : false,
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    48
        "lg" : "fr_cinecast",
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    49
        "autoPlay" : options.autoPlay,
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    50
        "directVideoTitle" : "",
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    51
        "urlAcData" : options.urlAcData,
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 842
diff changeset
    52
        "directVideoPath" : options.video,
842
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    53
        "host" : "http://allocine.fr"
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    54
    }
822
45083178c1d2 Corrections
veltr
parents: 819
diff changeset
    55
    
842
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    56
    if (typeof IriSP.__jsonMetadata["medias"][0].meta == "object" && typeof IriSP.__jsonMetadata["medias"][0].meta.subtitles == "string") {
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    57
        _flashVars.subTitlePath = IriSP.__jsonMetadata["medias"][0].meta.subtitles;
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    58
    }
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    59
    
842
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    60
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    61
    var params = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    62
        "allowScriptAccess" : "always",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    63
        "wmode": "opaque",
842
4ae2247a59f4 Changes for Cinecast
veltr
parents: 841
diff changeset
    64
        "flashvars" : IriSP.jQuery.param(_flashVars),
841
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    65
        "allowfullscreen" : true
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    66
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    67
    var atts = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    68
        id : this.container
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    69
    };
841
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    70
    swfobject.embedSWF(options.acPlayerUrl, this.container, options.width, options.height, "10", null, null, params, atts);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    71
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    72
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    73
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    74
IriSP.PopcornReplacement.allocine.prototype = new IriSP.PopcornReplacement.player("", {});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    75
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    76
IriSP.PopcornReplacement.allocine.prototype.ready = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    77
    this.player = document.getElementById(this.container);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    78
    this.player.addEventListener("onStateChange", "onAllocineStateChange");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    79
    this.player.cueVideoByUrl(this._options.video);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    80
    this.callbacks.onReady();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    81
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    82
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    83
IriSP.PopcornReplacement.allocine.prototype.progressHandler = function(progressInfo) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    84
    this.callbacks.onTime({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    85
        position: progressInfo.mediaTime
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    86
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    87
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    88
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    89
841
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    90
IriSP.PopcornReplacement.allocine.prototype.apiCall = function(_method, _arg) {
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    91
    if (this.player) {
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    92
        try {
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    93
            if (typeof _arg == "undefined") {
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    94
                return this.player.sendToActionScript(_method);
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    95
            } else {
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    96
                return this.player.sendToActionScript(_method, _arg);
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    97
            }
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    98
        } catch(e) {
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
    99
            console.error('Exception while requesting AcPlayer for "' + _method + (typeof _arg == "undefined" ? '' : '" with argument "' + _arg ) + '"\n', e);
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
   100
            return false;
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
   101
        }
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
   102
    } else {
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
   103
        return false;
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
   104
    }
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
   105
}
8da49ff273e0 Modifs cinecast
veltr
parents: 839
diff changeset
   106
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   107
IriSP.PopcornReplacement.allocine.prototype.stateHandler = function(state) {
839
4357aac4eb19 Added volume support
veltr
parents: 822
diff changeset
   108
    console.log("stateHandler");
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   109
    switch(state) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   110
        case 1:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   111
            this.callbacks.onPlay();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   112
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   113
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   114
        case 2:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   115
            this.callbacks.onPause();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   116
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   117
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   118
        case 3:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   119
            this.callbacks.onSeek({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   120
                position: this.player.getCurrentTime()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   121
            });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   122
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   123
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   124
        /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   125
        case 5:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   126
            this.callbacks.onReady();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   127
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   128
        */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   129
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   130
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   131
};