Platforms to show: All Mac Windows Linux Cross-Platform

Back to AVAudioPlayerMBS class.

AVAudioPlayerMBS.averagePowerForChannel(channel as Integer) as Double

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the average power for a given channel, in decibels, for the sound being played.

channelNumber: The audio channel whose average power value you want to obtain. Channel numbers are zero-indexed. A monaural signal, or the left channel of a stereo signal, has channel number 0.

Returns a floating-point representation, in decibels, of a given audio channel's current average power. A return value of 0 dB indicates full scale, or maximum power; a return value of -160 dB indicates minimum power (that is, near silence).

If the signal provided to the audio player exceeds ±full scale, then the return value may exceed 0 (that is, it may enter the positive range).

To obtain a current average power value, you must call the updateMeters method before calling this method.

AVAudioPlayerMBS.Constructor(Data as MemoryBlock, byref error as NSErrorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes and returns an audio player for playing a designated memory buffer.

data: A block of data containing a sound to play. The audio data must be in a format supported by Core Audio. For a list of supported formats, see "Using Audio" in Multimedia Programming Guide.
Error: Pass in the address of a nil-initialized NSError object. If an error occurs, upon return the NSError object describes the error. If you do not want error information, pass in NULL.

On success, you get an initialized AVAudioPlayer object. Else the handle property is 0 and the Error parameter contains a code that describes the problem.

See also:

AVAudioPlayerMBS.Constructor(Data as MemoryBlock, fileTypeHintUtiString as string, byref error as NSErrorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 14.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes and returns an audio player using the specified data and file type hint.

data: The data object containing the audio.
fileTypeHintUtiString: A UTI that is used as a file type hint. The supported UTIs are defined in File Format UTIs.
error: If an error occurs, upon return the NSError object describes the error.

The utiString file type hint tells the parser what kind of sound data to expect so that data that may possibly be corrupt, can be successfully parsed.

Available in OS X v10.9 and later, but plugin calls variant without filetypehint on older versins.

See also:

AVAudioPlayerMBS.Constructor(File as folderitem, byref error as NSErrorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes and returns an audio player for playing a designated sound file.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.mp3")
dim e as NSErrorMBS
dim u as new AVAudioPlayerMBS(f,e)
if e<>nil then
MsgBox e.localizedDescription
else
MsgBox str(u.duration)+" seconds"
end if

File: A folderitem identifying the sound file to play. The audio data must be in a format supported by Core Audio. For a list of supported formats, see "Using Audio" in Multimedia Programming Guide.
Error: If an error occurs, upon return the NSError object describes the error..

On success, you have an initialized AVAudioPlayer object. On failure, the Error parameter contains a code that describes the problem.

See also:

AVAudioPlayerMBS.Constructor(File as folderitem, fileTypeHintUtiString as string, byref error as NSErrorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 14.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes and returns an audio player using the specified URL and file type hint.

url: A URL identifying the sound file to play. The audio data must be in a format supported by Core Audio.
utiString: A UTI that is used as a file type hint. The supported UTIs are defined in File Format UTIs. See AVFileType* strings.
Error: If an error occurs, upon return the NSError object describes the error.

The utiString file type hint tells the parser what kind of sound data to expect so that files which are not self identifying, or possibly even corrupt, can be successfully parsed.

Available in OS X v10.9 and later, but plugin calls variant without hint for older versions.

See also:

AVAudioPlayerMBS.Constructor(URL as string, byref error as NSErrorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes and returns an audio player for playing a designated sound file.

url: A URL identifying the sound file to play. The audio data must be in a format supported by Core Audio. For a list of supported formats, see "Using Audio" in Multimedia Programming Guide.
Error: If an error occurs, upon return the NSError object describes the error..

On success, you have an initialized AVAudioPlayer object. On failure, the Error parameter contains a code that describes the problem.

See also:

AVAudioPlayerMBS.Constructor(URL as string, fileTypeHintUtiString as string, byref error as NSErrorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 14.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes and returns an audio player using the specified URL and file type hint.

url: A URL identifying the sound file to play. The audio data must be in a format supported by Core Audio.
utiString: A UTI that is used as a file type hint. The supported UTIs are defined in File Format UTIs. See AVFileType* strings.
Error: If an error occurs, upon return the NSError object describes the error.

The utiString file type hint tells the parser what kind of sound data to expect so that files which are not self identifying, or possibly even corrupt, can be successfully parsed.

Available in OS X v10.9 and later, but plugin calls variant without hint for older versions.

See also:

AVAudioPlayerMBS.pause

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Pauses playback; sound remains ready to resume playback from where it left off.

Calling pause leaves the audio player prepared to play; it does not release the audio hardware that was acquired upon calling play or prepareToPlay.

AVAudioPlayerMBS.peakPowerForChannel(channel as Integer) as Double

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the peak power for a given channel, in decibels, for the sound being played.

channelNumber: The audio channel whose peak power value you want to obtain. Channel numbers are zero-indexed. A monaural signal, or the left channel of a stereo signal, has channel number 0.

Returns a floating-point representation, in decibels, of a given audio channel's current peak power. A return value of 0 dB indicates full scale, or maximum power; a return value of -160 dB indicates minimum power (that is, near silence).

If the signal provided to the audio player exceeds ±full scale, then the return value may exceed 0 (that is, it may enter the positive range).

To obtain a current peak power value, you must call the updateMeters method before calling this method.

AVAudioPlayerMBS.play as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Plays a sound asynchronously.

Returns true on success, or false on failure.
Calling this method implicitly calls the prepareToPlay method if the audio player is not already prepared to play.

AVAudioPlayerMBS.playAtTime(time as Double = 0.0) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Plays a sound asynchronously, starting at a specified point in the audio output device's timeline.
Example
dim p as AVAudioPlayerMBS // your player

if p.playAtTime(p.deviceCurrentTime + 5.0) then
// playing in 5 seconds
else
// failed
end if

time: The number of seconds to delay playback, relative to the audio output device's current time.

Returns true on success, or false on failure.

To learn about the virtual audio output device's timeline, read the description for the deviceCurrentTime property.
Calling this method implicitly calls the prepareToPlay method if the audio player is not already prepared to play.

AVAudioPlayerMBS.prepareToPlay as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Prepares the audio player for playback by preloading its buffers.

Returns true on success, or false on failure.

Calling this method preloads buffers and acquires the audio hardware needed for playback, which minimizes the lag between calling the play method and the start of sound output.
Calling the stop method, or allowing a sound to finish playing, undoes this setup.

AVAudioPlayerMBS.stop

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Stops playback and undoes the setup needed for playback.

Calling this method, or allowing a sound to finish playing, undoes the setup performed upon calling the play or prepareToPlay methods.

The stop method does not reset the value of the currentTime property to 0. In other words, if you call stop during playback and then call play, playback resumes at the point where it left off.

AVAudioPlayerMBS.updateMeters

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Refreshes the average and peak power values for all channels of an audio player.

To obtain current audio power values, you must call this method before calling averagePowerForChannel or peakPowerForChannel.

The items on this page are in the following plugins: MBS AVFoundation Plugin.


The biggest plugin in space...