Show:

annie.Sound Class

Extends annie.Media
Defined in: libs/Sound.js:19
Module: annie

Available since 1.0.0

声音类

Methods

addEventListener

(
  • type
  • listener
  • useCapture
)
Void public

Inherited from annie.EventDispatcher: libs/EventDispatcher.js:109

Available since 1.0.0

给对象添加一个侦听

Parameters:

  • type String

    侦听类型

  • listener Function

    侦听后的回调方法,如果这个方法是类实例的方法,为了this引用的正确性,请在方法参数后加上.bind(this);

  • useCapture Boolean

    true 捕获阶段 false 冒泡阶段 默认 true

Returns:

Void:

Example:

 this.addEventListener(annie.Event.ADD_TO_STAGE,function(e){console.log(this);}.bind(this));

destroy

() public

Inherited from annie.AObject but overwritten in libs/Sound.js:64

Available since 1.1.1

从静态声音池中删除声音对象,如果一个声音再也不用了,建议先执行这个方法,再销毁

dispatchEvent

(
  • event
  • data
  • useCapture
)
Boolean public

Inherited from annie.EventDispatcher: libs/EventDispatcher.js:156

Available since 1.0.0

广播侦听

Parameters:

  • event annie.Event | String

    广播所带的事件对象,如果传的是字符串则自动生成一个annie.Event对象,事件类型就是传入进来的字符串的值

  • data Object

    广播后跟着事件一起传过去的其他任信息,默认值为null

  • useCapture Boolean

    true 捕获阶段 false 冒泡阶段 默认 true

Returns:

Boolean:

如果有收听者则返回true

Example:

 var mySprite=new annie.Sprite(),
 yourEvent=new annie.Event("yourCustomerEvent");
 yourEvent.data={a:1,b:2,c:"hello",d:{aa:1,bb:2}};
 mySprite.addEventListener("yourCustomerEvent",function(e){
     console.log(e.data);
 })
 mySprite.dispatchEvent(yourEvent);

hasEventListener

(
  • type
  • useCapture
)
Boolean public

Inherited from annie.EventDispatcher: libs/EventDispatcher.js:215

Available since 1.0.0

是否有添加过此类型的侦听

Parameters:

  • type String

    侦听类型

  • useCapture Boolean

    true 捕获阶段 false 冒泡阶段 默认 true

Returns:

Boolean:

如果有则返回true

Media

(
  • src
  • type
)

Inherited from annie.Media: libs/Media.js:29

Available since 1.0.0

构造函数

Parameters:

Example:

 var media = new annie.Media('http://test.annie2x.com/biglong/apiDemo/annieBitmap/resource/music.mp3', 'Audio');
     media.play();//媒体播放
     //media.pause();//暂停播放
     //media.stop();//停止播放

pause

(
  • isPause
)
public

Inherited from annie.Media: libs/Media.js:165

Available since 1.0.4

暂停播放,或者恢复播放

Parameters:

  • isPause Object

    默认为true;是否要暂停,如果要暂停,则暂停;否则则播放

play

(
  • start
  • loop
)
public

Inherited from annie.Media: libs/Media.js:113

Available since 1.0.0

开始播放媒体

Parameters:

  • start Number

    开始点 默认为0

  • loop Number

    循环次数 默认为1

play2

() Void public

Defined in libs/Sound.js:93

Available since 2.0.0

如果你的项目有背景音乐一直在播放,但可能项目里需要播放视频的时候,需要停止背景音乐或者其他需求, 视频播放完之后再恢复背景音乐播放。这个时候,你要考虑用户之前是否有主动关闭过背景音乐,有的话, 这个时候你再调用play()方法或者pause()方法就违背用户意愿。所以你应该调用play2()方法。 这个方法的原理就是如果用户之前关闭过了,那调用这个方法就不会播放声音,如果没关闭则会播放声音。

Returns:

Void:

removeAllEventListener

() Void public

Inherited from annie.EventDispatcher: libs/EventDispatcher.js:268

Available since 1.0.0

移除对象中所有的侦听

Returns:

Void:

removeEventListener

(
  • type
  • listener
  • useCapture
)
Void public

Inherited from annie.EventDispatcher: libs/EventDispatcher.js:239

Available since 1.0.0

移除对应类型的侦听

Parameters:

  • type String

    要移除的侦听类型

  • listener Function

    侦听时绑定的回调方法

  • useCapture Boolean

    true 捕获阶段 false 冒泡阶段 默认 true

Returns:

Void:

resumePlaySounds

() public static

Defined in libs/Sound.js:127

Available since 2.0.0

恢复当前所有正在停止的声音,当然一定要是annie.Sound类的声音

setAllSoundsVolume

(
  • volume
)
public static

Defined in libs/Sound.js:145

Available since 1.1.1

设置当前所有正在播放的声音,当然一定要是annie.Sound类的声音

Parameters:

  • volume Number

    音量大小,从0-1 在ios里 volume只能是0 或者1,其他无效

Sound

(
  • src
)
public

Defined in libs/Sound.js:44

Available since 1.0.0

构造函数

Parameters:

Example:

 var soundPlayer = new annie.Sound('http://test.annie2x.com/biglong/apiDemo/annieBitmap/resource/music.mp3');
     soundPlayer.play();//播放音乐
     //soundPlayer.pause();//暂停音乐
     //soundPlayer.stop();//停止音乐

stop

() public

Inherited from annie.Media: libs/Media.js:153

Available since 1.0.0

停止播放

stop2

() Void public

Defined in libs/Sound.js:80

Available since 2.0.0

作用和stop()相同,但你用这个方法停止声音了,用play2()方法才会有效

Returns:

Void:

stopAllSounds

() public static

Defined in libs/Sound.js:109

Available since 1.1.1

停止当前所有正在播放的声音,当然一定要是annie.Sound类的声音

Properties

_repeate

Number private

Inherited from annie.Media: libs/Media.js:72

Default: 1

instanceId

Number public

Inherited from annie.AObject: libs/EventDispatcher.js:31

Available since 1.0.0

每一个annie引擎对象都会有一个唯一的id码。

Example:

 //获取 annie引擎类对象唯一码
 console.log(this.instanceId);

instanceType

String public

Inherited from annie.AObject: libs/EventDispatcher.js:49

Available since 1.0.3

每一个annie类都有一个实例类型字符串,通过这个字符串,你能知道这个实例是从哪个类实例而来

isPlaying

Boolean

Inherited from annie.Media: libs/Media.js:58

Available since 2.0.0

Default: true

media

Video | Audio public

Inherited from annie.Media: libs/Media.js:43

Available since 1.0.0

html 标签 有可能是audio 或者 video

name

String

Inherited from annie.Media: libs/Media.js:65

给一个声音取一个名字,方便获取

type

String

Inherited from annie.Media: libs/Media.js:51

Available since 1.0.0

媒体类型 VIDEO 或者 AUDIO

volume

Unknown

Inherited from annie.Media: libs/Media.js:185

Available since 1.1.0

设置或者获取音量 从0-1

Events

annie.Event.ON_PLAY_END

Defined in libs/Sound.js:34

Available since 1.1.0

annie.Media相关媒体类的播放完成事件。像annie.Sound annie.Video都可以捕捉这种事件。

annie.Event.ON_PLAY_START

Defined in libs/Sound.js:39

Available since 1.1.0

annie.Media相关媒体类的开始播放事件。像annie.Sound annie.Video都可以捕捉这种事件。

annie.Event.ON_PLAY_UPDATE

Defined in libs/Sound.js:29

Available since 1.1.0

annie.Media相关媒体类的播放刷新事件。像annie.Sound annie.Video都可以捕捉这种事件。