Next and Prev buttons for Corax and Lorgar, debugging

This commit is contained in:
Blue 2019-01-03 03:26:42 +03:00
parent 22323b504f
commit 0e31c5fdf2
14 changed files with 394 additions and 72 deletions

View file

@ -188,7 +188,7 @@ var Controller = Subscribable.inherit({
}
if (this._registered) {
global.registerForeignController(pair.n, pair.c);
global.unregisterForeignController(pair.n, pair.c);
}
pair.c.off("serviceMessage", this._onControllerServiceMessage, this);

View file

@ -34,7 +34,6 @@ var Audio = File.inherit({
this._waitingForFrames = false;
}
this.initialized = true;
return ac;
},
_h_responseFrames: function(ev) {

View file

@ -63,6 +63,11 @@ var File = Controller.inherit({
if (ac) {
this.trigger("additionalChange");
}
if (!this.initialized) {
this.initialized = true;
this.trigger("ready");
}
},
"needData": function() {
if (this._need === 0) {

View file

@ -30,7 +30,7 @@ var LocalModel = Subscribable.inherit({
for (i = 0; i < this._foreignControllers.length; ++i) {
var pair = this._foreignControllers[i];
global.unsubscribeForeignController(pair.n, pair.c);
global.registerForeignController(pair.n, pair.c);
global.unregisterForeignController(pair.n, pair.c);
pair.c.destructor();
}

View file

@ -27,11 +27,8 @@ var Player = Controller.inherit({
this.views = Object.create(null);
this.mode = PlayerMode.straight.playback;
this._audio = null;
this._source = new Source();
this._asset = new AV.Asset(this._source);
this._player = new AV.Player(this._asset);
this._player.play();
this._createStateMachine();
this._createPlayingInfrastructure();
this.addHandler("get");
this.addHandler("viewsChange");
@ -54,6 +51,8 @@ var Player = Controller.inherit({
if (ItemType.reversed[t] !== undefined) {
switch (t) {
case ItemType.straight.playPause:
case ItemType.straight.prev:
case ItemType.straight.next:
var btn = new Button(address.clone());
btn.itemType = t;
this.controls[t] = btn;
@ -61,10 +60,10 @@ var Player = Controller.inherit({
this.trigger("newElement", btn, t);
break;
default:
this.trigger("serviceMessage", "An attempt to add ItemType " + ItemType.reversed[t] + " to controls of the Player, but it's not qualified to be a control");
this.trigger("serviceMessage", "An attempt to add ItemType " + ItemType.reversed[t] + " to controls of the Player, but it's not qualified to be a control", 1);
}
} else {
this.trigger("serviceMessage", "An unrecgnized item ItemType in Player: " + t);
this.trigger("serviceMessage", "An unrecgnized item ItemType in Player: " + t, 1);
}
},
_addView: function(type, address) {
@ -79,7 +78,7 @@ var Player = Controller.inherit({
if (ItemType.reversed[t] !== undefined) {
switch (t) {
case ItemType.straight.queue:
this.trigger("serviceMessage", "Queue is not supported yet in Player");
this.trigger("serviceMessage", "Queue is not supported yet in Player", 1);
break;
case ItemType.straight.currentPlayback:
ctrl = new Vocabulary(address.clone());
@ -96,10 +95,10 @@ var Player = Controller.inherit({
supported = false; //just to avoid adding with addController, since ImageById is not a controller
break;
default:
this.trigger("serviceMessage", "An attempt to add ItemType " + ItemType.reversed[t] + " to views of the Player, but it's not qualified to be a view");
this.trigger("serviceMessage", "An attempt to add ItemType " + ItemType.reversed[t] + " to views of the Player, but it's not qualified to be a view", 1);
}
} else {
this.trigger("serviceMessage", "An unrecgnized item ItemType in Player: " + t);
this.trigger("serviceMessage", "An unrecognized item ItemType in Player: " + t, 1);
}
if (supported) {
@ -110,6 +109,16 @@ var Player = Controller.inherit({
this.trigger("newElement", ctrl, t);
}
},
_createPlayingInfrastructure() {
if (this._source) {
this._source.reset();
this._asset.stop();
this._player.stop();
}
this._source = new Source();
this._asset = new AV.Asset(this._source);
this._player = new AV.Player(this._asset);
},
_createStateMachine: function() {
this._fsm = new StateMachine("initial", graphs[this.mode]);
this._fsm.on("stateChanged", this._onStateChanged, this);
@ -159,7 +168,7 @@ var Player = Controller.inherit({
size = remove.length();
for (i = 0; i < size; ++i) {
this._removeView(remove.at(i));
this._removeView(remove.at(i).valueOf());
}
size = add.length();
@ -179,6 +188,9 @@ var Player = Controller.inherit({
this._fsm.manipulation("noMoreFrames");
}
},
_onControllerReady: function() {
this._fsm.manipulation("controllerReady");
},
_onNewPlayBackElement: function(key, element) {
switch (key) {
case "image":
@ -191,6 +203,7 @@ var Player = Controller.inherit({
this._audio = new Audio(new Address(["music", element.toString()]));
this.addForeignController("Corax", this._audio);
this._audio.on("newFrames", this._onAudioNewFrames, this);
this._audio.on("ready", this._onControllerReady, this);
this._fsm.manipulation("controller");
}
break;
@ -199,7 +212,7 @@ var Player = Controller.inherit({
_onNewRemoveBackElement: function(key) {
switch (key) {
case "image":
this._removeView(new Uint64(ItemType.straight.picture));
this._removeView(ItemType.straight.picture);
break;
case "audio":
this.removeForeignController(this._audio);
@ -210,14 +223,35 @@ var Player = Controller.inherit({
_onStateChanged: function(e) {
switch (e.newState) {
case "initial":
if (e.manipulation === "noController") {
this.removeForeignController(this._audio);
this._audio.destructor();
this._audio = null;
this._createPlayingInfrastructure();
}
break;
case "initialPlaying":
if (e.manipulation === "noController") {
this._player.pause();
this.removeForeignController(this._audio);
this.audio.destructor();
this._audio = null;
this._createPlayingInfrastructure();
}
break;
case "controllerNotReady":
break
case "controllerNotReadyPlaying":
break
case "hasController":
break;
case "hasControllerPlaying":
if (this._audio.hasMore()) {
this._audio.requestMore();
this._player.play(); //todo temporal
} else {
this._fsm.manipulation("noMoreFrames");
}
@ -249,10 +283,30 @@ var Player = Controller.inherit({
}
},
_removeControl: function(type) {
//TODO
var ctrl = this.controls[type];
if (ctrl !== undefined) {
this.trigger("removeElement", type);
this.removeController(ctrl);
ctrl.destructor();
}
},
_removeView: function(type) {
//TODO
var view = this.views[type];
if (view !== undefined) {
this.trigger("removeElement", type);
if (type !== ItemType.straight.picture) {
this.removeController(view);
}
if (type === ItemType.straight.currentPlayback) {
if (this.views[ItemType.straight.picture]) {
this._removeView(ItemType.straight.picture);
}
this._fsm.manipulation("noController");
}
delete this.views[type];
view.destructor();
}
}
});
@ -261,6 +315,8 @@ ItemType.add("playPause");
ItemType.add("currentPlayback");
ItemType.add("queue");
ItemType.add("picture");
ItemType.add("prev");
ItemType.add("next");
var PlayerMode = new Enum("PlayerMode");
PlayerMode.add("playback");
@ -270,34 +326,48 @@ Player.ItemType = ItemType;
var graphs = Object.create(null);
graphs[PlayerMode.straight.playback] = {
"initial": {
controller: "hasController",
controller: "controllerNotReady",
play: "initialPlaying"
},
"initialPlaying": {
pause: "initial",
controller: "hasControllerPlaying"
controller: "controllerNotReadyPlaying"
},
"controllerNotReady": {
play: "controllerNotReadyPlaying",
controllerReady: "hasController"
},
"controllerNotReadyPlaying": {
pause: "controllerNotReady",
controllerReady: "hasControllerPlaying"
},
"hasController": {
newFrames: "paused",
play: "hasControllerPlaying"
play: "hasControllerPlaying",
noController: "initial"
},
"hasControllerPlaying": {
newFrames: "playing",
pause: "hasController"
pause: "hasController",
noController: "initialPlaying"
},
"paused": {
play: "playing",
noController: "initial",
noMoreFrames: "pausedAllLoaded"
},
"pausedAllLoaded": {
play: "playingAllLoaded"
play: "playingAllLoaded",
noController: "initial"
},
"playing": {
pause: "paused",
noMoreFrames: "playingAllLoaded"
noMoreFrames: "playingAllLoaded",
noController: "initialPlaying"
},
"playingAllLoaded": {
pause: "pausedAllLoaded"
pause: "pausedAllLoaded",
noController: "initialPlaying"
}
}