浏览代码

added loop, getPosition, playAt, stop

Nicolas Cannasse 12 年之前
父节点
当前提交
aaa5e0504e
共有 1 个文件被更改,包括 23 次插入1 次删除
  1. 23 1
      hxd/res/Sound.hx

+ 23 - 1
hxd/res/Sound.hx

@@ -3,16 +3,29 @@ package hxd.res;
 class Sound extends Resource {
 	
 	public var volume(default, set) = 1.0;
+	public var loop : Bool;
 	
 	#if flash
 	var snd : flash.media.Sound;
 	var channel : flash.media.SoundChannel;
 	#end
 	
+	public function getPosition() : Float {
+		#if flash
+		return channel.position;
+		#else
+		return 0.;
+		#end
+	}
+	
 	public function play() {
+		playAt(0);
+	}
+	
+	public function playAt( startPosition : Float ) {
 		#if flash
 		if( snd != null ) {
-			channel = snd.play();
+			channel = snd.play(startPosition);
 			volume = volume;
 			return;
 		}
@@ -33,6 +46,15 @@ class Sound extends Resource {
 		#end
 	}
 	
+	public function stop() {
+		#if flash
+		if( channel != null ) {
+			channel.stop();
+			channel = null;
+		}
+		#end
+	}
+	
 	function set_volume( v : Float ) {
 		volume = v;
 		#if flash