Agora RTC Objective-C API Reference Refactor

Instance Methods
<AgoraMusicPlayerProtocol> Protocol Reference

Inherits <NSObjectAgoraRtcMediaPlayerProtocol>.

## Instance Methods
(NSInteger) | - openMediaWithSongCode:startPos:
(NSInteger) | - setPlayMode:

## Method Documentation

## ◆ openMediaWithSongCode:startPos:

- (NSInteger) openMediaWithSongCode: |  | (NSInteger) | songCode
startPos: |  | (NSInteger) | startPos

Opens a music resource by its resource ID.

Before calling this method, make sure the music resource you want to play has been fully loaded. You can check whether the music resource has been preloaded by calling the `isPreloadedWithSongCode:` method, or by listening to the `onPreLoadEvent:songCode:percent:lyricUrl:state:reason:` callback.

After calling this method, the `AgoraRtcMediaPlayer:didChangedToState:reason:` callback is triggered. Once you receive the playback state `AgoraMediaPlayerStateOpenCompleted`, you can call the `play` method to start playback.

Note
  If the music resource you want to open is protected by digital rights management, you must use this method to open it. For music resources that are not protected by digital rights, you can choose to open them using either this method or the `open:startPos:` method under the `AgoraRtcMediaPlayerProtocol` class.

Parameters

  songCode | The ID of the music resource, used to identify the music content.
  startPos | The starting playback position in milliseconds. The default value is 0.

Returns
  - 0: The method call succeeds.
  - < 0: The method call fails. See `Error Codes` for details and recommended solutions.

## ◆ setPlayMode:

- (NSInteger) setPlayMode: |  | (AgoraMusicPlayMode) | mode |

Sets the playback mode for a music resource.

You can call this method to enable the original vocals, accompaniment, or vocal guide. If you do not call this method, accompaniment is played by default. If the music resource does not contain accompaniment, the original vocals are played. Applicable scenarios: In entertainment scenarios such as online karaoke or live shows, if you need to play copyrighted music provided by the Agora Content Center, you can call this method to set the playback mode. Call timing: You must call this method after `createMusicPlayerWithDelegate:`.

Note
  You can obtain detailed information about the music resource through the `onMusicCollectionResult:result:reason:` callback. From the `result` parameter, you can learn which playback modes are supported for the copyrighted music.

Parameters

  mode | The playback mode. See `AgoraMusicPlayMode` for details.

Returns
  - 0: The method call succeeds.
  - < 0: The method call fails. See `Error Codes` for details and troubleshooting.
    - -2: Invalid parameter. Please reset the parameter.