PCMPlayer
public class PCMPlayer : NSObject
PCMのプレイヤークラス。
本プレイヤーは、新しい音声データが追加されると再生待ちバッファの最後尾に追加します。 再生中は、再生待ちバッファの先頭から音声データを再生します。 伝送遅延等の影響で音声データの追加タイミングがばらつくと、 バッファ長が延び、音声データの追加から再生されるまでの時間(バッファリング時間)が大きくなる場合があります。
ライブモードで再生する場合は、バッファリング時間が蓄積して再生までに時間がかかるのを防ぐため、
再生待ちバッファが liveModeMaxBufferingTime
の長さを超えた場合に、
バッファ長が liveModeMaxBufferingTime
になるまでバッファの先頭をスキップして再生を継続します。
これにより、ライブモードではバッファリング時間が liveModeMaxBufferingTime
を超えることはありません。
通信が不安定な場合に liveModeMaxBufferingTime
を小さく設定しすぎると、
スキップが頻繁に起こり、再生がとぎれとぎれになる場合があります。
このような場合には、 liveModeMaxBufferingTime
の値を大きめに設定してください。
-
音声フォーマットのデフォルト値(
.pcmInt16
)。Declaration
Swift
public static let DEFAULT_PLAY_FORMAT: IntdashAudioFormat
-
サンプリングレートのデフォルト値( 48000 )。
Declaration
Swift
public static let DEFAULT_SAMPLE_RATE: Double
-
再生に必要な音声サンプル数のデフォルト値( 1024 )。
Declaration
Swift
public static let DEFAULT_AUDIO_OUTPUT_FRAME: Int
-
チャンネル数のデフォルト値( 1チャンネル )。
Declaration
Swift
public static let DEFAULT_CHANNELS: Int
-
ライブモードかどうかを表すフラグのデフォルト値(
true
)。Declaration
Swift
public static let DEFAULT_LIVE_MODE_FLAG: Bool
-
ライブモード時のバッファリング時間の最大値のデフォルト値( 300ms )
Declaration
Swift
public static let DEFAULT_LIVE_MODE_MAX_BUFFERING_TIME: TimeInterval
-
音声フォーマット。
Declaration
Swift
public let playerFormat: IntdashAudioFormat
-
サンプリングレート。
Declaration
Swift
public let sampleRate: Double
-
チャンネル数。
Declaration
Swift
public let channels: Int
-
AVAudioFormat の streamDescription。
Declaration
Swift
public let streamDescription: AudioStreamBasicDescription
-
出力するフレームに含まれるサンプル数。
Declaration
Swift
public let outputFrameSize: Int
-
ライブモードかどうかを表すフラグ。
Declaration
Swift
public var isLiveMode: Bool
-
ライブモード時のバッファリング時間の最大値。
Declaration
Swift
public var liveModeMaxBufferingTime: TimeInterval
-
ミュートフラグ。
Declaration
Swift
public var isMuted: Bool
-
オブジェクトを識別するためのタグ。
Declaration
Swift
public var tag: Int
-
このクラスが使用する Delegate。
Declaration
Swift
public weak var delegate: PCMPlayerDelegate?
-
PCMPlayer を生成します。
Declaration
Swift
public override init()
-
PCMPlayer を生成します。
Declaration
Swift
public init(commonFormat: AVAudioCommonFormat, sampleRate: Double = PCMPlayer.DEFAULT_SAMPLE_RATE, channels: Int = PCMPlayer.DEFAULT_CHANNELS, outputFrameSize: Int) throws
Parameters
commonFormat
音声フォーマット
sampleRate
サンプリングレート
channels
チャンネル数
outputFrameSize
出力するフレームのサイズ
-
PCMPlayer を生成します。
Declaration
Swift
public init(pcmFormat: PCMFormat, outputFrameSize: Int) throws
Parameters
pcmFormat
音声フォーマット
outputFrameSize
出力するフレームのサイズ
-
音声を再生します。
Declaration
Swift
public func play(completion: @escaping (_ result: Bool) -> ())
Parameters
completion
処理完了時のコールバック
result
処理成功、失敗フラグ
-
再生対象のデータを追加します。
Declaration
Swift
public func append(sampleData: Data, time: TimeInterval = MediaSystemClock.shared.rtcDate.timeIntervalSince1970)
Parameters
sampleData
サンプルデータ
time
タイムスタンプ
-
再生対象のデータを追加します。
Declaration
Swift
public func append(sampleBufferPtr: UnsafeMutableRawPointer, bufferLength: Int, time: TimeInterval = MediaSystemClock.shared.rtcDate.timeIntervalSince1970)
Parameters
sampleBufferPtr
サンプルバッファーへのポインタ
bufferLength
バッファーの長さ
time
タイムスタンプ
-
再生を一時停止します。
Declaration
Swift
public func pause()
-
バッファーをクリアします。
Declaration
Swift
public func clearBuffer()
-
再生を停止します。
Declaration
Swift
public func stop(_ completion: (() -> ())? = nil)
Parameters
completion
処理完了時のコールバック
-
割り当てを解除します。
Declaration
Swift
public func dispose()