IMediaPlayer.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. using System;
  2. namespace Agora.Rtc
  3. {
  4. ///
  5. /// <summary>
  6. /// This class provides media player functions and supports multiple instances.
  7. /// </summary>
  8. ///
  9. public abstract class IMediaPlayer
  10. {
  11. ///
  12. /// <summary>
  13. /// Releases all the resources occupied by the media player.
  14. /// </summary>
  15. ///
  16. public abstract void Dispose();
  17. ///
  18. /// <summary>
  19. /// Gets the ID of the media player.
  20. /// </summary>
  21. ///
  22. /// <returns>
  23. /// >= 0: Success. The ID of the media player.&lt; 0: Failure.
  24. /// </returns>
  25. ///
  26. public abstract int GetId();
  27. ///
  28. /// <summary>
  29. /// Adds callback event for media player.
  30. /// </summary>
  31. ///
  32. /// <param name="engineEventHandler"> Callback events to be added. </param>
  33. ///
  34. public abstract void InitEventHandler(IMediaPlayerSourceObserver engineEventHandler);
  35. ///
  36. /// <summary>
  37. /// Registers an audio frame observer object.
  38. /// You need to implement the IMediaPlayerAudioFrameObserver class in this method and register callbacks according to your scenarios. After you successfully register the video frame observer, the SDK triggers the registered callbacks each time a video frame is received.
  39. /// </summary>
  40. ///
  41. /// <param name="observer"> The audio frame observer, reporting the reception of each audio frame. See IMediaPlayerAudioFrameObserver .</param>
  42. ///
  43. public abstract void RegisterAudioFrameObserver(IMediaPlayerAudioFrameObserver observer);
  44. ///
  45. /// <summary>
  46. /// Registers an audio frame observer object.
  47. /// </summary>
  48. ///
  49. /// <param name="observer"> The audio frame observer, reporting the reception of each audio frame. See IAudioFrameObserver .</param>
  50. ///
  51. /// <param name="mode"> The use mode of the audio frame. See RAW_AUDIO_FRAME_OP_MODE_TYPE .</param>
  52. ///
  53. public abstract void RegisterAudioFrameObserver(IMediaPlayerAudioFrameObserver observer, RAW_AUDIO_FRAME_OP_MODE_TYPE mode);
  54. ///
  55. /// <summary>
  56. /// Unregisters an audio frame observer.
  57. /// </summary>
  58. ///
  59. public abstract void UnregisterAudioFrameObserver();
  60. ///
  61. /// @ignore
  62. ///
  63. public abstract void RegisterMediaPlayerAudioSpectrumObserver(IAudioSpectrumObserver observer, int intervalInMS);
  64. ///
  65. /// @ignore
  66. ///
  67. public abstract void UnregisterMediaPlayerAudioSpectrumObserver();
  68. ///
  69. /// <summary>
  70. /// Opens the media resource.
  71. /// This method is called asynchronously. If you need to play a media file, make sure you receive the OnPlayerSourceStateChanged callback reporting PLAYER_STATE_OPEN_COMPLETED before calling the Play method to play the file.
  72. /// </summary>
  73. ///
  74. /// <param name="url"> The path of the media file. Both local path and online path are supported.On the Android platform, if you need to open a file in URI format, use Open .</param>
  75. ///
  76. /// <param name="startPos"> The starting position (ms) for playback. Default value is 0.</param>
  77. ///
  78. /// <returns>
  79. /// 0: Success.&lt; 0: Failure.
  80. /// </returns>
  81. ///
  82. public abstract int Open(string url, Int64 startPos);
  83. ///
  84. /// <summary>
  85. /// Opens the custom media resource file.
  86. /// Deprecated:This method is deprecated. This method allows you to open custom media resource files. For example, you can call this method to open encrypted media resources.
  87. /// </summary>
  88. ///
  89. /// <param name="playerId"> The ID of the media player.</param>
  90. ///
  91. /// <param name="startPos"> The starting position (ms) for playback. The default value is 0.</param>
  92. ///
  93. /// <param name="provider"> The callback for custom media resource files. See IMediaPlayerCustomDataProvider .</param>
  94. ///
  95. /// <returns>
  96. /// 0: Success.&lt; 0: Failure.
  97. /// </returns>
  98. ///
  99. public abstract int OpenWithCustomSource(Int64 startPos, IMediaPlayerCustomDataProvider provider);
  100. ///
  101. /// <summary>
  102. /// Opens a media file and configures the playback scenarios.
  103. /// This method supports opening media files of different sources, including a custom media source, and allows you to configure the playback scenarios.
  104. /// </summary>
  105. ///
  106. /// <param name="source"> Media resources. See MediaSource .</param>
  107. ///
  108. /// <returns>
  109. /// 0: Success.&lt; 0: Failure.
  110. /// </returns>
  111. ///
  112. public abstract int OpenWithMediaSource(MediaSource source);
  113. ///
  114. /// @ignore
  115. ///
  116. public abstract int SetSoundPositionParams(float pan, float gain);
  117. ///
  118. /// <summary>
  119. /// Plays the media file.
  120. /// After calling Open or Seek, you can call this method to play the media file.
  121. /// </summary>
  122. ///
  123. /// <returns>
  124. /// 0: Success.&lt; 0: Failure.
  125. /// </returns>
  126. ///
  127. public abstract int Play();
  128. ///
  129. /// <summary>
  130. /// Pauses the playback.
  131. /// </summary>
  132. ///
  133. /// <returns>
  134. /// 0: Success.&lt; 0: Failure.
  135. /// </returns>
  136. ///
  137. public abstract int Pause();
  138. ///
  139. /// <summary>
  140. /// Stops playing the media track.
  141. /// </summary>
  142. ///
  143. /// <returns>
  144. /// 0: Success.&lt; 0: Failure.
  145. /// </returns>
  146. ///
  147. public abstract int Stop();
  148. ///
  149. /// <summary>
  150. /// Resumes playing the media file.
  151. /// </summary>
  152. ///
  153. /// <returns>
  154. /// 0: Success.&lt; 0: Failure.
  155. /// </returns>
  156. ///
  157. public abstract int Resume();
  158. ///
  159. /// <summary>
  160. /// Seeks to a new playback position.
  161. /// After successfully calling this method, you will receive the OnPlayerEvent callback, reporting the result of the seek operation to the new playback position.To play the media file from a specific position, do the following:Call this method to seek to the position you want to begin playback.Call the Play method to play the media file.
  162. /// </summary>
  163. ///
  164. /// <param name="newPos"> The new playback position (ms).</param>
  165. ///
  166. /// <returns>
  167. /// 0: Success.&lt; 0: Failure.
  168. /// </returns>
  169. ///
  170. public abstract int Seek(Int64 newPos);
  171. ///
  172. /// <summary>
  173. /// Gets the duration of the media resource.
  174. /// </summary>
  175. ///
  176. /// <param name="duration"> Output parameter. The total duration (ms) of the media file.</param>
  177. ///
  178. /// <returns>
  179. /// 0: Success.&lt; 0: Failure.
  180. /// </returns>
  181. ///
  182. public abstract int GetDuration(ref Int64 duration);
  183. ///
  184. /// <summary>
  185. /// Gets current local playback progress.
  186. /// </summary>
  187. ///
  188. /// <param name="pos"> The playback position (ms) of the audio effect file.</param>
  189. ///
  190. /// <returns>
  191. /// Returns the current playback progress (ms) if the call succeeds.&lt; 0: Failure. See MEDIA_PLAYER_ERROR .
  192. /// </returns>
  193. ///
  194. public abstract int GetPlayPosition(ref Int64 pos);
  195. ///
  196. /// <summary>
  197. /// Gets the number of the media streams in the media resource.
  198. /// Call this method after calling Open .
  199. /// </summary>
  200. ///
  201. /// <param name="count"> Output parameter. The number of the media streams in the media resource.</param>
  202. ///
  203. /// <returns>
  204. /// 0: Success.&lt; 0: Failure. See MEDIA_PLAYER_ERROR .
  205. /// </returns>
  206. ///
  207. public abstract int GetStreamCount(ref Int64 count);
  208. ///
  209. /// <summary>
  210. /// Gets the detailed information of the media stream.
  211. /// Call this method after calling GetStreamCount .
  212. /// </summary>
  213. ///
  214. /// <param name="index"> The index of the media stream.</param>
  215. ///
  216. /// <param name="info"> An output parameter. The detailed information of the media stream. See PlayerStreamInfo .</param>
  217. ///
  218. /// <returns>
  219. /// 0: Success.&lt; 0: Failure.
  220. /// </returns>
  221. ///
  222. public abstract int GetStreamInfo(Int64 index, ref PlayerStreamInfo info);
  223. ///
  224. /// <summary>
  225. /// Sets the loop playback.
  226. /// If you want to loop, call this method and set the number of the loops.When the loop finishes, the SDK triggers OnPlayerSourceStateChanged and reports the playback state as PLAYER_STATE_PLAYBACK_ALL_LOOPS_COMPLETED.
  227. /// </summary>
  228. ///
  229. /// <param name="loopCount"> The number of times the audio effect loops:</param>
  230. ///
  231. /// <returns>
  232. /// 0: Success.&lt; 0: Failure.
  233. /// </returns>
  234. ///
  235. public abstract int SetLoopCount(int loopCount);
  236. ///
  237. /// <summary>
  238. /// Sets the channel mode of the current audio file.
  239. /// Call this method after calling Open .
  240. /// </summary>
  241. ///
  242. /// <param name="speed"> The playback speed. Agora recommends that you limit this value to between 50 and 400, defined as follows:50: Half the original speed.100: The original speed.400: 4 times the original speed.</param>
  243. ///
  244. /// <returns>
  245. /// 0: Success.&lt; 0: Failure.
  246. /// </returns>
  247. ///
  248. public abstract int SetPlaybackSpeed(int speed);
  249. ///
  250. /// <summary>
  251. /// Selects the audio track used during playback.
  252. /// 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.You need to call this method after calling GetStreamInfo to get the audio stream index value.
  253. /// </summary>
  254. ///
  255. /// <param name="index"> The index of the audio track.</param>
  256. ///
  257. /// <returns>
  258. /// 0: Success.&lt; 0: Failure.
  259. /// </returns>
  260. ///
  261. public abstract int SelectAudioTrack(int index);
  262. ///
  263. /// <summary>
  264. /// Sets the private options for the media player.
  265. /// The media player supports setting private options by key and value. Under normal circumstances, you do not need to know the private option settings, and just use the default option settings.Ensure that you call this method before Open .If you need to push streams with SEI into the CDN, callSetPlayerOption [1/2] ("sei_data_with_uuid", 1); otherwise, the loss of SEI might occurs.
  266. /// </summary>
  267. ///
  268. /// <param name="key"> The key of the option.</param>
  269. ///
  270. /// <param name="value"> The value of the key.</param>
  271. ///
  272. /// <returns>
  273. /// 0: Success.&lt; 0: Failure.
  274. /// </returns>
  275. ///
  276. public abstract int SetPlayerOption(string key, int value);
  277. ///
  278. /// <summary>
  279. /// Sets the private options for the media player.
  280. /// The media player supports setting private options by key and value. Under normal circumstances, you do not need to know the private option settings, and just use the default option settings. Ensure that you call this method before Open .
  281. /// If you need to push streams with SEI into the CDN, callSetPlayerOption [1/2] ("sei_data_with_uuid", 1); otherwise, the loss of SEI might occurs.
  282. /// </summary>
  283. ///
  284. /// <param name="key"> The key of the option.</param>
  285. ///
  286. /// <param name="value"> The value of the key.</param>
  287. ///
  288. /// <returns>
  289. /// 0: Success.&lt; 0: Failure.
  290. /// </returns>
  291. ///
  292. public abstract int SetPlayerOption(string key, string value);
  293. ///
  294. /// @ignore
  295. ///
  296. public abstract int TakeScreenshot(string filename);
  297. ///
  298. /// @ignore
  299. ///
  300. public abstract int SelectInternalSubtitle(int index);
  301. ///
  302. /// @ignore
  303. ///
  304. public abstract int SetExternalSubtitle(string url);
  305. ///
  306. /// <summary>
  307. /// Gets current playback state.
  308. /// </summary>
  309. ///
  310. /// <returns>
  311. /// The current playback state. See MEDIA_PLAYER_STATE .
  312. /// </returns>
  313. ///
  314. public abstract MEDIA_PLAYER_STATE GetState();
  315. ///
  316. /// <summary>
  317. /// Sets whether to mute the media file.
  318. /// </summary>
  319. ///
  320. /// <param name="muted"> Whether to mute the media file:true: Mute the media file.false: (Default) Unmute the media file.</param>
  321. ///
  322. /// <returns>
  323. /// 0: Success.&lt; 0: Failure.
  324. /// </returns>
  325. ///
  326. public abstract int Mute(bool muted);
  327. ///
  328. /// <summary>
  329. /// Reports whether the media resource is muted.
  330. /// </summary>
  331. ///
  332. /// <param name="muted"> Output parameter. Whether the media file is muted:true: Mute the media file.false: The media file is unmuted.</param>
  333. ///
  334. /// <returns>
  335. /// 0: Success.&lt; 0: Failure.
  336. /// </returns>
  337. ///
  338. public abstract int GetMute(ref bool muted);
  339. ///
  340. /// <summary>
  341. /// Adjusts the local playback volume.
  342. /// </summary>
  343. ///
  344. /// <param name="volume"> The local playback volume, which ranges from 0 to 100:0: Mute.100: (Default) The original volume.</param>
  345. ///
  346. /// <returns>
  347. /// 0: Success.&lt; 0: Failure.
  348. /// </returns>
  349. ///
  350. public abstract int AdjustPlayoutVolume(int volume);
  351. ///
  352. /// <summary>
  353. /// Gets the local playback volume.
  354. /// </summary>
  355. ///
  356. /// <param name="volume"> Output parameter. The local playback volume, which ranges from 0 to 100:0: Mute.100: (Default) The original volume.</param>
  357. ///
  358. /// <returns>
  359. /// 0: Success.&lt; 0: Failure.
  360. /// </returns>
  361. ///
  362. public abstract int GetPlayoutVolume(ref int volume);
  363. ///
  364. /// <summary>
  365. /// Adjusts the volume of the media file for publishing.
  366. /// After connected to the Agora server, you can call this method to adjust the volume of the media file heard by the remote user.
  367. /// </summary>
  368. ///
  369. /// <param name="volume"> The volume, which ranges from 0 to 400:0: Mute.100: (Default) The original volume.400: Four times the original volume (amplifying the audio signals by four times).</param>
  370. ///
  371. /// <returns>
  372. /// 0: Success.&lt; 0: Failure.
  373. /// </returns>
  374. ///
  375. public abstract int AdjustPublishSignalVolume(int volume);
  376. ///
  377. /// <summary>
  378. /// Gets the volume of the media file for publishing.
  379. /// </summary>
  380. ///
  381. /// <param name="volume"> Output parameter. The remote playback volume.</param>
  382. ///
  383. /// <returns>
  384. /// 0: Success.&lt; 0: Failure.
  385. /// </returns>
  386. ///
  387. public abstract int GetPublishSignalVolume(ref int volume);
  388. ///
  389. /// <summary>
  390. /// Sets the view.
  391. /// </summary>
  392. ///
  393. /// <returns>
  394. /// 0: Success.&lt; 0: Failure.
  395. /// </returns>
  396. ///
  397. public abstract int SetView();
  398. ///
  399. /// <summary>
  400. /// Sets the render mode of the media player.
  401. /// </summary>
  402. ///
  403. /// <param name="renderMode"> Sets the render mode of the view. See RENDER_MODE_TYPE .</param>
  404. ///
  405. /// <returns>
  406. /// 0: Success.&lt; 0: Failure.
  407. /// </returns>
  408. ///
  409. public abstract int SetRenderMode(RENDER_MODE_TYPE renderMode);
  410. ///
  411. /// <summary>
  412. /// Sets the channel mode of the current audio file.
  413. /// 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.Call this method after calling Open .This method only applies to stereo audio files.
  414. /// </summary>
  415. ///
  416. /// <param name="mode"> The channel mode. See AUDIO_DUAL_MONO_MODE .</param>
  417. ///
  418. /// <returns>
  419. /// 0: Success.&lt; 0: Failure.
  420. /// </returns>
  421. ///
  422. public abstract int SetAudioDualMonoMode(AUDIO_DUAL_MONO_MODE mode);
  423. ///
  424. /// @ignore
  425. ///
  426. public abstract string GetPlayerSdkVersion();
  427. ///
  428. /// @ignore
  429. ///
  430. public abstract string GetPlaySrc();
  431. ///
  432. /// <summary>
  433. /// Sets the pitch of the current media resource.
  434. /// Call this method after calling Open .
  435. /// </summary>
  436. ///
  437. /// <param name="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.</param>
  438. ///
  439. /// <returns>
  440. /// 0: Success.&lt; 0: Failure.
  441. /// </returns>
  442. ///
  443. public abstract int SetAudioPitch(int pitch);
  444. ///
  445. /// @ignore
  446. ///
  447. public abstract int SetSpatialAudioParams(SpatialAudioParams spatial_audio_params);
  448. ///
  449. /// <summary>
  450. /// Opens a media resource and requests all the CDN routes of the media resources through the self-developed scheduling center.
  451. /// This method is called asynchronously. If you need to play a media file, make sure you receive the OnPlayerSourceStateChanged callback reporting PLAYER_STATE_OPEN_COMPLETED before calling the Play method to play the file.After you call this method, Agora opens the media resources and tries to obtain all the CDN routes for playing the media resource. By default, Agora uses the first CDN route for playing, and you can call the SwitchAgoraCDNLineByIndex method to switch routes.If you want to ensure the security of the connection and media files, to determine the sign and the ts fields for authentication. Once the fields are determined, use them as the query parameter of the URL to update the URL of the media resource. For example:The URL of the media file to be opened: rtmp://$domain/$appName/$streamNameThe URL updated by the authentication of the media file to be opened: rtmp://$domain/$appName/$streamName?ts=$ts&sign=$signAuthentication information:sign: An encrypted string calculated according to the MD5 algorithm based on authKey, appName, streamName, and ts. You need to for your authKey.ts: The timestamp when the authentication information expires. You can set the validity period of the authentication information according to your scenarios. For example, 24h or 1h30m20s.
  452. /// </summary>
  453. ///
  454. /// <param name="src"> The URL of the media resource.</param>
  455. ///
  456. /// <param name="startPos"> The starting position (ms) for playback. The default value is 0. This value can be empty if the media resource to be played is live streams.</param>
  457. ///
  458. /// <returns>
  459. /// 0: Success.&lt; 0: Failure.
  460. /// </returns>
  461. ///
  462. public abstract int OpenWithAgoraCDNSrc(string src, Int64 startPos);
  463. ///
  464. /// <summary>
  465. /// Gets the number of CDN routes for the media resource.
  466. /// </summary>
  467. ///
  468. /// <returns>
  469. /// Returns the number of CDN routes for the media resource, if the method call succeeds.≤ 0: Failure.
  470. /// </returns>
  471. ///
  472. public abstract int GetAgoraCDNLineCount();
  473. ///
  474. /// <summary>
  475. /// Changes the CDN route for playing the media resource.
  476. /// After calling OpenWithAgoraCDNSrc to open the media resource, you can call this method if you want to change the CDN routes for playing the media resource.Call this method after calling OpenWithAgoraCDNSrc .You can call this method either before or after Play . If you call this method before Play, the switch does not take effect immediately. The SDK waits for the playback to complete before switching the CDN line of the media resource.
  477. /// </summary>
  478. ///
  479. /// <param name="index"> The index of the CDN routes.</param>
  480. ///
  481. /// <returns>
  482. /// 0: Success.&lt; 0: Failure.
  483. /// </returns>
  484. ///
  485. public abstract int SwitchAgoraCDNLineByIndex(int index);
  486. ///
  487. /// <summary>
  488. /// Gets the CDN routes index of the current media resource.
  489. /// </summary>
  490. ///
  491. /// <returns>
  492. /// The number of CDN routes for the media resource, if the method call succeeds. The value range is [0, GetAgoraCDNLineCount()).&lt; 0: Failure.
  493. /// </returns>
  494. ///
  495. public abstract int GetCurrentAgoraCDNIndex();
  496. ///
  497. /// <summary>
  498. /// Enables/Disables the automatic switch of the CDN routes for playing the media resource.
  499. /// You can call this method if you want the SDK to automatically switch the CDN routes according to your network conditions.Call this method before OpenWithAgoraCDNSrc .
  500. /// </summary>
  501. ///
  502. /// <param name="enable"> Whether to enable the automatic switch of the CDN routes for playing the media resource:true: Enables the automatic switch of the CDN routes.false: (Default) Disables the automatic switch of the CDN routes.</param>
  503. ///
  504. /// <returns>
  505. /// 0: Success.&lt; 0: Failure.
  506. /// </returns>
  507. ///
  508. public abstract int EnableAutoSwitchAgoraCDN(bool enable);
  509. ///
  510. /// <summary>
  511. /// Renew the authentication information for the URL of the media resource to be played.
  512. /// When the authentication information expires (exceeds the ts field), you can call the OpenWithAgoraCDNSrc method to reopen the media resource or the SwitchAgoraCDNSrc method to switch the media resource, and then pass in the authenticated URL (with the ts field updated) of the media resource.If your authentication information expires when you call the SwitchAgoraCDNLineByIndex to switch the CDN route for playing the media resource, you need to call this method to pass in the updated authentication information to update the authentication information of the media resource URL. After updating the authentication information, you need to call SwitchAgoraCDNLineByIndex to complete the route switching.To avoid frequent expiration of authentication information, ensure that you set the ts field appropriately or according to the scenario requirements.
  513. /// </summary>
  514. ///
  515. /// <param name="token"> The authentication field. See the sign field of the authentication information.</param>
  516. ///
  517. /// <param name="ts"> The timestamp when the authentication information expires. See the ts field of the authentication information.</param>
  518. ///
  519. /// <returns>
  520. /// 0: Success.&lt; 0: Failure.
  521. /// </returns>
  522. ///
  523. public abstract int RenewAgoraCDNSrcToken(string token, Int64 ts);
  524. ///
  525. /// <summary>
  526. /// Switches the media resource being played.
  527. /// If you want to ensure the security of the connection and media files, to determine the sign and the ts fields for authentication. Once the fields are determined, use them as the query parameter of the URL to update the URL of the media resource. For example:The URL of the media file to be opened: rtmp://$domain/$appName/$streamNameThe URL updated by the authentication of the media file to be opened: rtmp://$domain/$appName/$streamName?ts=$ts&sign=$signAuthentication information:sign: An encrypted string calculated according to the MD5 algorithm based on authKey, appName, streamName, and ts. You need to for your authKey.ts: The timestamp when the authentication information expires. You can set the validity period of the authentication information according to your scenarios. For example, 24h or 1h30m20s.If you want to customize the CDN routes for playing the media resource, call this method to switch media resources. Agora changes the CDN route through the self-developed scheduling center to improve the viewing experience. If you do not need to customize CDN routes for playing the media resource, call the SwitchSrc method to switch media resources.
  528. /// Call this method after calling OpenWithAgoraCDNSrc .You can call this method either before or after Play . If you call this method before Play, the SDK waits for you to call Play before completing the route switch.
  529. /// </summary>
  530. ///
  531. /// <param name="src"> The URL of the media resource.</param>
  532. ///
  533. /// <param name="syncPts"> Whether to synchronize the playback position (ms) before and after the switch:true: Synchronize the playback position before and after the switch.false: (Default) Do not synchronize the playback position before and after the switch.falseMake sure to set this parameter as if you need to play live streams, or the switch fails. If you need to play on-demand streams, you can set the value of this parameter according to your scenarios.</param>
  534. ///
  535. /// <returns>
  536. /// 0: Success.&lt; 0: Failure.
  537. /// </returns>
  538. ///
  539. public abstract int SwitchAgoraCDNSrc(string src, bool syncPts = false);
  540. ///
  541. /// <summary>
  542. /// Switches the media resource being played.
  543. /// You can call this method to switch the media resource to be played according to the current network status. For example:When the network is poor, the media resource to be played is switched to a media resource address with a lower bitrate.When the network is good, the media resource to be played is switched to a media resource address with a higher bitrate.After calling this method, if you receive the OnPlayerEvent event in the PLAYER_EVENT_SWITCH_COMPLETE callback, the switch is successful; If you receive the OnPlayerEvent event in the PLAYER_EVENT_SWITCH_ERROR callback, the switch fails.Ensure that you call this method after Open .To ensure normal playback, pay attention to the following when calling this method:Do not call this method when playback is paused.Do not call the Seek method during switching.Before switching the media resource, make sure that the playback position does not exceed the total duration of the media resource to be switched.
  544. /// </summary>
  545. ///
  546. /// <param name="src"> The URL of the media resource.</param>
  547. ///
  548. /// <param name="syncPts"> Whether to synchronize the playback position (ms) before and after the switch:true: Synchronize the playback position before and after the switch.false: (Default) Do not synchronize the playback position before and after the switch.Make sure to set this parameter as false if you need to play live streams, or the switch fails. If you need to play on-demand streams, you can set the value of this parameter according to your scenarios.</param>
  549. ///
  550. /// <returns>
  551. /// 0: Success.&lt; 0: Failure.
  552. /// </returns>
  553. ///
  554. public abstract int SwitchSrc(string src, bool syncPts = true);
  555. ///
  556. /// <summary>
  557. /// Preloads a media resource.
  558. /// 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.If the preload is successful and you want to play the media resource, call PlayPreloadedSrc ; if you want to clear the playlist, call Stop .Agora does not support preloading duplicate media resources to the playlist. However, you can preload the media resources that are being played to the playlist again.
  559. /// </summary>
  560. ///
  561. /// <param name="src"> The URL of the media resource.</param>
  562. ///
  563. /// <param name="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.</param>
  564. ///
  565. /// <returns>
  566. /// 0: Success.&lt; 0: Failure.
  567. /// </returns>
  568. ///
  569. public abstract int PreloadSrc(string src, Int64 startPos);
  570. ///
  571. /// <summary>
  572. /// Plays preloaded media resources.
  573. /// After calling the PreloadSrc 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 OnPlayerSourceStateChanged callback which reports the PLAYER_STATE_PLAYING 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 to preload the media resource to the playlist again before playing. If you want to clear the playlist, call the Stop method.If you call this method when playback is paused, this method does not take effect until playback is resumed.
  574. /// </summary>
  575. ///
  576. /// <param name="src"> The URL of the media resource in the playlist must be consistent with the src set by the PreloadSrc method; otherwise, the media resource cannot be played.</param>
  577. ///
  578. /// <returns>
  579. /// 0: Success.&lt; 0: Failure.
  580. /// </returns>
  581. ///
  582. public abstract int PlayPreloadedSrc(string src);
  583. ///
  584. /// <summary>
  585. /// Unloads media resources that are preloaded.
  586. /// This method cannot release the media resource being played.
  587. /// </summary>
  588. ///
  589. /// <param name="src"> The URL of the media resource.</param>
  590. ///
  591. /// <returns>
  592. /// 0: Success.&lt; 0: Failure.
  593. /// </returns>
  594. ///
  595. public abstract int UnloadSrc(string src);
  596. }
  597. }