Agora RTC Objective-C API Reference Refactor

Instance Methods | Class Methods
AgoraMusicContentCenter Class Reference

Inherits <NSObject>.

## Instance Methods
(NSInteger) | - renewToken:
(NSInteger) | - registerEventDelegate:
(id< AgoraMusicPlayerProtocol > _Nullable) | - createMusicPlayerWithDelegate:
(NSInteger) | - destroyMusicPlayer:
(NSString *) | - getMusicCharts
(NSString *) | - getMusicCollectionWithMusicChartId:page:pageSize:jsonOption:
(NSString *) | - searchMusicWithKeyWord:page:pageSize:jsonOption:
(NSInteger) | - preloadWithSongCode:jsonOption:
(NSString *) | - preloadWithSongCode:
(NSInteger) | - isPreloadedWithSongCode:
(NSInteger) | - removeCacheWithSongCode:
(NSArray *) | - getCaches
(NSInteger) | - getInternalSongCode:jsonOption:
(NSString *) | - getLyricWithSongCode:lyricType:
(NSString *) | - getSongSimpleInfoWithSongCode:

## Class Methods
(instancetype _Nullable) | + sharedContentCenterWithConfig:
(void) | + destroy

## Method Documentation

## ◆ sharedContentCenterWithConfig:

+ (instancetype _Nullable) sharedContentCenterWithConfig: |  | (AgoraMusicContentCenterConfig *) | config |

Create an AgoraMusicContentCenter instance.

Parameters

  config | Configurations for the AgoraMusicContentCenter instance. For details, see AgoraMusicContentCenterConfig.

Returns
  An shared instance of AgoraMusicContentCenter

## ◆ renewToken:

- (NSInteger) renewToken: |  | (NSString *_Nonnull) | token |

Renew token of music content center

Parameters

  token | The new token.

Returns
  - 0: Success.
  - < 0: Failure.

## ◆ registerEventDelegate:

- (NSInteger) registerEventDelegate: |  | (id< AgoraMusicContentCenterEventDelegate > _Nullable) | eventDelegate |

Register an event delegate, only the last delegate is working.

Parameters

  eventDelegate | the object who need AgoraRtcMediaPlayerDelegate method to get the player information , if you want remove the delegate, just pass nil

Returns
  - 0: Success.
  - < 0: Failure.

## ◆ createMusicPlayerWithDelegate:

- (id<AgoraMusicPlayerProtocol> _Nullable) createMusicPlayerWithDelegate: |  | (id< AgoraRtcMediaPlayerDelegate > _Nullable) | delegate |

Creates a music player source object and return its pointer.

Parameters

  delegate | The object who need AgoraRtcMediaPlayerDelegate method to get the player information

Returns
  - The pointer to an object who realize the AgoraMusicPlayerProtocol, if the method call succeeds.
  - The empty pointer NULL, if the method call fails.

## ◆ destroyMusicPlayer:

- (NSInteger) destroyMusicPlayer: |  | (id< AgoraMusicPlayerProtocol >) | musicPlayer |

Destroy a music player source object and return result.

Parameters

  musicPlayer | The music player.

Returns
  - 0: Success.
  - < 0: Failure.

## ◆ getMusicCharts

- (NSString *) getMusicCharts |  |  |

Get music chart collection of music.If the method call success, get result from the AgoraMusicContentCenterEventDelegate - (void)onMusicChartsResult:(NSString *)requestId status:(AgoraMusicContentCenterStatusCode)status result:(NSArray<AgoraMusicChartInfo*> *)result; match the callback "requestId" parameter to get the request result.

Returns
  The request identification

## ◆ getMusicCollectionWithMusicChartId:page:pageSize:jsonOption:

- (NSString *) getMusicCollectionWithMusicChartId: |  | (NSInteger) | musicChartId
page: |  | (NSInteger) | page
pageSize: |  | (NSInteger) | pageSize
jsonOption: |  | (NSString *_Nullable) | jsonOption

Get hot music list by hotType and page info.If the method call success, get result from the AgoraMusicContentCenterEventDelegate - (void)onMusicCollectionResult:(NSString *)requestId status:(AgoraMusicContentCenterStatusCode)status result:(AgoraMusicCollection *)result; match the callback "requestId" parameter to get the request result.

Parameters

  musicChartId | The music chart id obtained from getMusicCharts.
  page | The page of the music chart, starting from 1
  pageSize | The page size, max is 50.
  jsonOption | The ext param, default is null.

Returns
  The request identification

## ◆ searchMusicWithKeyWord:page:pageSize:jsonOption:

- (NSString *) searchMusicWithKeyWord: |  | (NSString *) | keyWord
page: |  | (NSInteger) | page
pageSize: |  | (NSInteger) | pageSize
jsonOption: |  | (NSString *_Nullable) | jsonOption

Search music by keyword and page info. get result from the AgoraMusicContentCenterEventDelegate - (void)onMusicCollectionResult:(NSString *)requestId status:(AgoraMusicContentCenterStatusCode)status result:(AgoraMusicCollection *)result; match the callback "requestId" parameter to get the request result.

Parameters

  keyWord | The key word to search.
  page | The page of the music search result, starting from 1
  pageSize | The page size, max is 50.
  jsonOption | The ext param, default is null.

Returns
  The request identification

## ◆ preloadWithSongCode:jsonOption:

- (NSInteger) preloadWithSongCode: |  | (NSInteger) | songCode
jsonOption: |  | (NSString *_Nullable) | jsonOption

Preload a media file with specified parameters.

Deprecated:
  This method is deprecated. Use preload(songCode:) instead.

Parameters

  songCode | The identify of the media file that you want to play.
  jsonOption | The ext param, default is null.

Returns
  - 0: Success.
  - < 0: Failure.

## ◆ preloadWithSongCode:

- (NSString *) preloadWithSongCode: |  | (NSInteger) | songCode |

Preload a media file with specified parameters.

Parameters

  songCode | The identify of the media file that you want to play.

Returns
  The request identification

## ◆ isPreloadedWithSongCode:

- (NSInteger) isPreloadedWithSongCode: |  | (NSInteger) | songCode |

Preload a media file with specified parameters.

Parameters

  songCode | The identify of the media file that you want to play.

Returns
  - 0: Success.
  - < 0: Failure.

## ◆ removeCacheWithSongCode:

- (NSInteger) removeCacheWithSongCode: |  | (NSInteger) | songCode |

Remove a media file cache

Parameters

  songCode | The identifier of the media file that you want to play.

Returns
  - 0: Success; the cached media file is removed.
  - < 0: Failure.

## ◆ getCaches

- (NSArray *) getCaches |  |  |

Get media cache files.

Returns
  The caches Array contains songCode and status of the music.

## ◆ getInternalSongCode:jsonOption:

- (NSInteger) getInternalSongCode: |  | (NSInteger) | songCode
jsonOption: |  | (NSString *_Nullable) | jsonOption

Get internal songCodeKey from songCode and jsonOption

Parameters

  songCode | The identifier of the media file.
  jsonOption | An extention parameter. The default value is null. it’s a json-format string and the `key` and `value` can be customized according to your scenarios.

Returns
  - Internal songCode key, if the method call succeeds.
  - The number less than zero, if the method call fails.

## ◆ getLyricWithSongCode:lyricType:

- (NSString *) getLyricWithSongCode: |  | (NSInteger) | songCode
lyricType: |  | (NSInteger) | lyricType

Get lyric of the song. get result from the AgoraMusicContentCenterEventDelegate - (void)onLyricResult:(NSString*)requestId lyricUrl:(NSString*)lyricUrl; match the callback "requestId" parameter to get the request result.

Parameters

  songCode | The identify of the media file that you want to play.
  lyricType | The type of the lyric file. may be 0:xml or 1:lrc.

Returns
  The request identification

## ◆ getSongSimpleInfoWithSongCode:

- (NSString *) getSongSimpleInfoWithSongCode: |  | (NSInteger) | songCode |

Gets the metadata of a specific music. Once this method is called, the SDK triggers the onSongSimpleInfoResult callback to report the metadata of the music.

Parameters

  songCode | The identify of the media file that you want to play.

Returns
  The request identification

## ◆ destroy

+ (void) destroy |  |  |

Destroy the shared instance of AgoraMusicContentCenter

Note
  If you call the method, you should call it brefore AgoraRtcEngineKit destroy