Quickstart
Media Pull service enables you to inject external media streams into real-time Agora channels. This page explains how to use Media Pull and Video SDK to publish external media to a channel.
Prerequisites
Before starting, ensure that you have implemented the Video SDK quickstart in your project.
Implement Media Pull
This section guides you through the implementation of Media Pull basic features in your app.
Enable Media Pull
To enable Media Pull, take the following steps:
-
Log in to Agora Console, and click Projects in the left navigation panel.
-
On the My Projects page, find the project for which you want to enable Media Pull and click Edit.
-
Under All Features, select Media Pull.
-
Click Enable. If you do not see the Enable button, contact support.
You can view usage statistics on the Agora Console Usage page.
Create a Cloud Player
To pull external media into the channel, you create a cloud player using the Create RESTful API. Refer to the following points when calling the API:
- Region configuration:
- Set the
region
parameter to match the location of your media streaming source. For example, usena
if the source is in North America. - Ensure the
region
value is in lowercase.
- Set the
- Request header:
- Assign a unique string to the
X-Request-ID
field for troubleshooting. The Agora server returns anX-Custom-request-ID
field in the response header.
- Assign a unique string to the
- User identification:
- Choose either
UID
oraccount
for the cloud player's user name; never set both. - Ensure each cloud player in a channel has a unique user name.
- Choose either
- Avoid duplicates:
- Use the
name
field to manage cloud players. Names must be unique within a project. Attempting to create a cloud player with a duplicate name returns a409 (Conflict)
status code.
- Use the
- Supported formats:
- Ensure that the media stream uses supported audio/video formats and protocols to avoid failures.
- Idle timeout:
- Set the
idleTimeout
parameter to a suitable value. The default value of 300 seconds is recommended. The cloud player automatically destroys the stream after this period of inactivity.
- Set the
- Cloud player creation events:
- Upon successful creation, the message notification server sends a payload with the
status
field set toconnecting
, indicating the server is connecting to the media stream or probing audio and video data.
- Upon successful creation, the message notification server sends a payload with the
Refer to the RESTful API Reference to update player settings or to delete a cloud player.
Query Cloud Players
To retrieve a list of cloud players under a project, use the List RESTful API. Refer to the following points when calling the API:
- For the first query, omit the
pageToken
parameter. The response includes the current page and anextPageToken
. - Use the
nextPageToken
in subsequent queries to retrieve the next page from the list of of cloud players. - When
nextPageToken
is0
, all cloud players under the project have been listed.
Cloud players are returned in ascending order based on their creation time (createTs
).
Subscribe to a cloud stream
Once the cloud player is successfully created, it joins your channel as a virtual user with the specified uid
. You can now subscribe to this user's stream in your app.
- Android
- iOS
- macOS
- Web
- Flutter
rtcEngine.setEventHandler(new IRtcEngineEventHandler() { @Override public void onUserPublished(int uid, int mediaType) { super.onUserPublished(uid, mediaType); // Subscribe to the user's media stream rtcEngine.subscribe(uid, mediaType); }});
// Callback when a remote user publishes a streamfunc rtcEngine(_ engine: AgoraRtcEngineKit, didUserPublish uid: UInt, with mediaType: AgoraMediaType) { print("User published: (uid), mediaType: (mediaType)") // Subscribe to the user's media stream agoraEngine.subscribeStream(uid, mediaType: mediaType)}
// Callback when a remote user publishes a streamfunc rtcEngine(_ engine: AgoraRtcEngineKit, didUserPublish uid: UInt, with mediaType: AgoraMediaType) { print("User published: (uid), mediaType: (mediaType)") // Subscribe to the user's media stream agoraEngine.subscribeStream(uid, mediaType: mediaType)}
client.on("user-published", async (user, mediaType) => { await client.subscribe(user, mediaType); if (mediaType === "video") { const remoteVideoTrack = user.videoTrack; remoteVideoTrack.play("remote-video-container"); // Replace with your container element } else if (mediaType === "audio") { const remoteAudioTrack = user.audioTrack; remoteAudioTrack.play(); }});
// Set up event handlers_engine.registerEventHandler( RtcEngineEventHandler( onUserPublished: (int uid, MediaType mediaType, int elapsed) { print("User published: $uid, mediaType: $mediaType"); // Subscribe to the user's media stream _engine.subscribeStream(uid: uid, mediaType: mediaType); } ));