AudioSource improvements
This commit is contained in:
@@ -41,6 +41,7 @@ class AudioSource {
|
||||
private var id:UInt;
|
||||
private var playing:Bool;
|
||||
private var pauseTime:Int;
|
||||
private var __completed:Bool;
|
||||
private var __length:Null<Int>;
|
||||
private var __loops:Int;
|
||||
private var __position:Vector4;
|
||||
@@ -70,6 +71,7 @@ class AudioSource {
|
||||
|
||||
this.loops = loops;
|
||||
id = 0;
|
||||
__completed = false;
|
||||
|
||||
__position = new Vector4 ();
|
||||
|
||||
@@ -159,7 +161,7 @@ class AudioSource {
|
||||
#elseif flash
|
||||
|
||||
if (channel != null) channel.stop ();
|
||||
var channel = buffer.src.play (pauseTime / 1000);
|
||||
channel = buffer.src.play (pauseTime / 1000 + offset, loops + 1);
|
||||
|
||||
#elseif lime_console
|
||||
|
||||
@@ -388,6 +390,7 @@ class AudioSource {
|
||||
|
||||
}
|
||||
|
||||
__completed = true;
|
||||
onComplete.dispatch ();
|
||||
|
||||
#end
|
||||
@@ -410,7 +413,15 @@ class AudioSource {
|
||||
|
||||
#elseif flash
|
||||
|
||||
return Std.int (channel.position);
|
||||
if (channel != null) {
|
||||
|
||||
return Std.int (channel.position) - offset;
|
||||
|
||||
} else {
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#elseif lime_console
|
||||
|
||||
@@ -419,9 +430,17 @@ class AudioSource {
|
||||
|
||||
#else
|
||||
|
||||
var time = Std.int (AL.getSourcef (id, AL.SEC_OFFSET) * 1000) - offset;
|
||||
if (time < 0) return 0;
|
||||
return time;
|
||||
if (__completed) {
|
||||
|
||||
return length;
|
||||
|
||||
} else {
|
||||
|
||||
var time = Std.int (AL.getSourcef (id, AL.SEC_OFFSET) * 1000) - offset;
|
||||
if (time < 0) return 0;
|
||||
return time;
|
||||
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
@@ -463,13 +482,18 @@ class AudioSource {
|
||||
|
||||
}
|
||||
|
||||
var timeRemaining = length - (value + offset);
|
||||
var timeRemaining = length - value;
|
||||
|
||||
if (timeRemaining > 0) {
|
||||
|
||||
__completed = false;
|
||||
timer = new Timer (timeRemaining);
|
||||
timer.run = timer_onRun;
|
||||
|
||||
} else {
|
||||
|
||||
__completed = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -557,7 +581,7 @@ class AudioSource {
|
||||
|
||||
#elseif flash
|
||||
|
||||
return Std.int (buffer.src.length);
|
||||
return Std.int (buffer.src.length) - offset;
|
||||
|
||||
#elseif lime_console
|
||||
|
||||
|
||||
Reference in New Issue
Block a user