|
Agora RTC Objective-C API Reference
Refactor
|
Inherits <NSObject>.
| - (int) getMediaPlayerId |
Gets the ID of the media player.
| - (int) open: | (NSString *) | url | |
| startPos: | (NSInteger) | startPos | |
Opens the media resource.
Call timing: This method can be called either before or after joining the channel. Related callbacks: After calling this method, the SDK triggers the AgoraRtcMediaPlayer:didChangedToState:reason: callback. After receiving the report of the playback status as AgoraMediaPlayerStateOpenCompleted, you can call the play method to play the media file.
| url | The path of the media file. Both local path and online path are supported. |
| startPos | The starting position (ms) for playback. Default value is 0. |
| - (int) openWithMediaSource: | (AgoraMediaSource *) | source |
Opens a media file and configures the playback scenarios.
This method supports opening different types of media files, including files starting with ipod-library://, and setting the playback options. Call timing: You can call this method either before or after joining a channel.
AgoraRtcMediaPlayer:didChangedToState:reason: callback reporting AgoraMediaPlayerStateOpenCompleted before calling the play method to play the file.| source | Media resources. See AgoraMediaSource. |
| - (int) openWithAgoraCDNSrc: | (NSString *) | src | |
| startPos: | (NSInteger) | startPos | |
Open the Agora CDN media source.
| src | The src of the media file that you want to play. |
| startPos | The playback position (ms). |
| - (int) getAgoraCDNLineCount |
| - (int) switchAgoraCDNLineByIndex: | (int) | index |
Switch Agora CDN lines.
| index | Specific line. |
| - (int) getCurrentAgoraCDNIndex |
| - (int) enableAutoSwitchAgoraCDN: | (BOOL) | enable |
Enable automatic CDN line switching.
| enable | Whether enable. |
| - (int) renewAgoraCDNSrcToken: | (NSString *) | token | |
| ts: | (NSInteger) | ts | |
Update the CDN source token and timestamp.
| token | token. |
| ts | ts. |
| - (int) switchAgoraCDNSrc: | (NSString *) | src | |
| syncPts: | (BOOL) | syncPts | |
Switch the CDN source.
| src | Specific line. |
| syncPts | Live streaming must be set to false. |
| - (int) play |
Plays the media file.
Call timing: - Call this method after calling open:startPos: or openWithMediaSource: opening a media file and receiving a AgoraRtcMediaPlayer:didChangedToState:reason: callback reporting the status as AgoraMediaPlayerStateOpenCompleted.
seekToPosition:.| - (int) pause |
Pauses the playback.
Call timing: You can call this method either before or after joining a channel.
| - (int) stop |
Stops playing the media track.
After calling this method to stop playback, if you want to play again, you need to call open:startPos: or openWithMediaSource: to open the media resource. Call timing: Call this method after play.
| - (int) resume |
Resumes playing the media file.
| - (int) seekToPosition: | (NSInteger) | position |
Seeks to a new playback position.
seekToPosition: after the playback has completed (upon receiving callback AgoraRtcMediaPlayer:didChangedToState:reason: reporting playback status as AgoraMediaPlayerStatePlayBackCompleted or AgoraMediaPlayerStatePlayBackAllLoopsCompleted ), the SDK will play the media file from the specified position. At this point, you will receive callback AgoraRtcMediaPlayer:didChangedToState:reason: reporting playback status as AgoraMediaPlayerStatePlaying.seekToPosition: while the playback is paused, upon successful call of this method, the SDK will seek to the specified position. To resume playback, call resume or playCall timing: You can call this method either before or after joining a channel. Related callbacks: After successfully calling this method, you will receive the AgoraRtcMediaPlayer:didOccurEvent:elapsedTime:message: callback, reporting the result of the seek operation to the new playback position.
| position | The new playback position (ms). |
| - (int) setAudioPitch: | (NSInteger) | pitch |
Sets the pitch of the current media resource.
open:startPos:.| pitch | Sets the pitch of the local music file by the chromatic scale. The default value is 0, which means keeping the original pitch. The value ranges from -12 to 12, and the pitch value between consecutive values is a chromatic value. The greater the absolute value of this parameter, the higher or lower the pitch of the local music file. |
| - (NSInteger) getDuration |
Gets the duration of the media resource.
| - (NSInteger) getAudioBufferDelay |
Gets the audio buffer delay when playing the media file.
| - (NSInteger) getPosition |
Gets current local playback progress.
AgoraMediaPlayerReason. | - (NSInteger) getStreamCount |
Gets the number of the media streams in the media resource.
open:startPos: and receive the AgoraRtcMediaPlayer:didChangedToState:reason: callback reporting the state AgoraMediaPlayerStateOpenCompleted.AgoraMediaPlayerReason. | - (AgoraRtcMediaStreamInfo *_Nullable) getStreamByIndex: | (int) | index |
Gets the detailed information of the media stream.
Call timing: Call this method after calling getStreamCount.
| index | The index of the media stream. This parameter must be less than the return value of getStreamCount. |
AgoraRtcMediaStreamInfo.nil is returned, if the method call fails. | - (int) setLoopCount: | (int) | loopCount |
Sets the loop playback.
If you want to loop, call this method and set the number of the loops. When the loop finishes, the SDK triggers AgoraRtcMediaPlayer:didChangedToState:reason: and reports the playback state as AgoraMediaPlayerStatePlayBackAllLoopsCompleted.
| loopCount | The number of times the audio effect loops:
|
| - (int) setPlaybackSpeed: | (int) | speed |
Sets the channel mode of the current audio file.
Call this method after calling open:startPos:.
| speed | The playback speed. Agora recommends that you set this to a value between 30 and 400, defined as follows:
|
| - (int) selectAudioTrack: | (int) | index |
Selects the audio track used during playback.
After getting the track index of the audio file, you can call this method to specify any track to play. For example, if different tracks of a multi-track file store songs in different languages, you can call this method to set the playback language.
getStreamByIndex: to get the audio stream index value.| index | The index of the audio track. |
| - (int) selectMultiAudioTrack: | (NSInteger) | playoutTrackIndex | |
| publishTrackIndex: | (NSInteger) | publishTrackIndex | |
Selects the audio tracks that you want to play on your local device and publish to the channel respectively.
You can call this method to determine the audio track to be played on your local device and published to the channel. Before calling this method, you need to open the media file with the openWithMediaSource: method and set enableMultiAudioTrack in AgoraMediaSource as YES. Applicable scenarios: For example, in KTV scenarios, the host can choose to play the original sound locally and publish the accompaniment track to the channel.
| playoutTrackIndex | The index of audio tracks for local playback. You can obtain the index through getStreamByIndex:. |
| publishTrackIndex | The index of audio tracks to be published in the channel. You can obtain the index through getStreamByIndex:. |
| - (int) takeScreenshot: | (NSString *) | filename |
take screenshot while playing video
| filename | the filename of screenshot file |
| - (int) selectInternalSubtitle: | (int) | index |
select internal subtitles in video
| index | the index of the internal subtitles |
| - (int) setExternalSubtitle: | (NSString *) | url |
set an external subtitle for video
| url | The URL of the subtitle file that you want to load. |
| - (AgoraMediaPlayerState) getPlayerState |
Gets current playback state.
AgoraMediaPlayerState. | - (int) mute: | (BOOL) | isMute |
Sets whether to mute the media file.
Call timing: You can call this method either before or after joining a channel.
| isMute | Whether to mute the media file:
|
| - (BOOL) getMute |
Reports whether the media resource is muted.
YES: Reports whether the media resource is muted.NO: Reports whether the media resource is muted. | - (int) adjustPlayoutVolume: | (int) | volume |
Adjusts the local playback volume.
Call timing: This method can be called either before or after joining the channel.
| volume | The local playback volume, which ranges from 0 to 100:
|
| - (int) getPlayoutVolume |
Gets the local playback volume.
| - (int) adjustPublishSignalVolume: | (int) | volume |
Adjusts the volume of the media file for publishing.
After connected to the Agora server, you can call this method to adjust the volume of the media file heard by the remote user. Call timing: This method can be called either before or after joining the channel.
| volume | The volume, which ranges from 0 to 400:
|
| - (int) getPublishSignalVolume |
Gets the volume of the media file for publishing.
| - (int) setPlayerOption: | (NSString *) | key | |
| value: | (NSInteger) | value | |
Sets media player options.
The media player supports setting options through key and value. The difference between this method and setPlayerOptionString:value: is that the value parameter of this method is of type Int, while the value of setPlayerOptionString:value: is of type String. These two methods cannot be used together. Applicable scenarios: Scenarios that require technical previews or special customization features. In general, you do not need to call this method; you can simply use the default options provided by the media player. Call timing: Call this method before the open:startPos: or openWithMediaSource: method.
| key | The key of the option. |
| value | The value of the key. |
| - (int) setPlayerOptionString: | (NSString *) | key | |
| value: | (NSString *) | value | |
Sets media player options.
The media player supports setting options through key and value. The difference between this method and setPlayerOption:value: is that the value parameter of this method is of type String, while the value of setPlayerOption:value: is of type String. These two methods cannot be used together. Applicable scenarios: Scenarios that require technical previews or special customization features. In general, you do not need to call this method; you can simply use the default options provided by the media player. Call timing: Call this method before the open:startPos: or openWithMediaSource: method.
| key | The key of the option. |
| value | The value of the key. |
| - (int) setView: | (View *_Nullable) | view |
Sets the view.
Call timing: You can call this method either before or after joining a channel.
| view | The render view. |
| - (int) setRenderMode: | (AgoraMediaPlayerRenderMode) | mode |
Sets the render mode of the media player.
| mode | Sets the render mode of the view. See AgoraVideoRenderMode. |
| - (NSString *) getPlaySrc |
Gets the path of the media resource being played.
| - (int) switchSrc: | (NSString *) | src | |
| syncPts: | (BOOL) | syncPts | |
Switches the media resource being played.
You can call this method to switch the media resource to be played according to the current network status. For example:
AgoraRtcMediaPlayer:didOccurEvent:elapsedTime:message: callback report the AgoraMediaPlayerEventSwitchComplete event, the switching is successful. If the switching fails, the SDK will automatically retry 3 times. If it still fails, you will receive the AgoraRtcMediaPlayer:didOccurEvent:elapsedTime:message: callback reporting the AgoraMediaPlayerEventSwitchError event indicating an error occurred during media resource switching.open:startPos:.seekToPosition: method during switching.| src | The URL of the media resource. |
| syncPts | Whether to synchronize the playback position (ms) before and after the switch:
|
| - (int) preloadSrc: | (NSString *) | src | |
| startPos: | (int) | startPos | |
Preloads a media resource.
You can call this method to preload a media resource into the playlist. If you need to preload multiple media resources, you can call this method multiple times. After calling this method, if you receive the AgoraMediaPlayerPreloadEventComplete event in the AgoraRtcMediaPlayer:didPreloadEvent: callback, the preload is successful; If you receive the AgoraMediaPlayerPreloadEventError event in the AgoraRtcMediaPlayer:didPreloadEvent: callback, the preload fails. If the preload is successful and you want to play the media resource, call playPreloadedSrc:; if you want to clear the playlist, call stop.
open:startPos: or openWithMediaSource: to open the media resource successfully.| src | The URL of the media resource. |
| startPos | The starting position (ms) for playing after the media resource is preloaded to the playlist. When preloading a live stream, set this parameter to 0. |
| - (int) unloadSrc: | (NSString *) | src |
Unloads media resources that are preloaded.
| src | The URL of the media resource. |
| - (int) playPreloadedSrc: | (NSString *) | src |
Plays preloaded media resources.
After calling the preloadSrc:startPos: method to preload the media resource into the playlist, you can call this method to play the preloaded media resource. After calling this method, if you receive the AgoraRtcMediaPlayer:didChangedToState:reason: callback which reports the AgoraMediaPlayerStatePlaying state, the playback is successful. If you want to change the preloaded media resource to be played, you can call this method again and specify the URL of the new media resource that you want to preload. If you want to replay the media resource, you need to call preloadSrc:startPos: to preload the media resource to the playlist again before playing. If you want to clear the playlist, call the stop method.
| src | The URL of the media resource in the playlist must be consistent with the src set by the preloadSrc:startPos: method; otherwise, the media resource cannot be played. |
| - (int) setAudioDualMonoMode: | (AgoraAudioDualMonoMode) | mode |
Sets the channel mode of the current audio file.
In a stereo music file, the left and right channels can store different audio data. According to your needs, you can set the channel mode to original mode, left channel mode, right channel mode, or mixed channel mode. For example, in the KTV scenario, the left channel of the music file stores the musical accompaniment, and the right channel stores the singing voice. If you only need to listen to the accompaniment, call this method to set the channel mode of the music file to left channel mode; if you need to listen to the accompaniment and the singing voice at the same time, call this method to set the channel mode to mixed channel mode.
open:startPos:.| mode | The channel mode. See AgoraAudioDualMonoMode. |
| - (BOOL) setAudioFrameDelegate: | (id< AgoraRtcMediaPlayerAudioFrameDelegate > _Nullable) | delegate |
Registers & unregister the player audio observer
| delegate | observer object, pass nil to unregister |
| - (BOOL) setVideoFrameDelegate: | (id< AgoraRtcMediaPlayerVideoFrameDelegate > _Nullable) | delegate |
Registers the video observer object of the media player.
When calling this method to register a video observer, you can register callbacks in the AgoraRtcMediaPlayerVideoFrameDelegate class as needed. After you successfully register the video frame observer, the SDK triggers the registered callbacks each time a video frame is received.
| delegate | The delegate instance. See AgoraRtcMediaPlayerVideoFrameDelegate. Set the value as nil to release the instance. |
| - (int) registerMediaPlayerAudioSpectrumDelegate: | (id< AgoraAudioSpectrumDelegate > _Nullable) | delegate | |
| intervalInMS: | (NSUInteger) | intervalInMS | |
| - (int) unregisterMediaPlayerAudioSpectrumDelegate: | (id< AgoraAudioSpectrumDelegate > _Nullable) | delegate |