At Video SDK, we’re building tools to help companies create world-class collaborative products with capabilities of live audio/videos, compose cloud recordings/rtmp/hls and interaction APIs.
📱 Download the sample Android app here: https://appdistribution.firebase.dev/i/a8156572b0936799
- Interactive live stream (HLS) is a media streaming protocol for delivering visual and audio media to viewers over the internet.
- Interactive live stream (HLS) allows you to distribute content and ensure excellent viewing experiences across devices, playback platforms, and network conditions. It is the ideal protocol for streaming video to large audiences scattered across geographies.
- VideoSDK also allows you to configure the interactive livestream layouts in numerous ways like by simply setting different prebuilt layouts in the configuration or by providing your own custom template to do the livestream according to your layout choice.
Note :
With VideoSDK, you can also use your own custom designed layout template to livestream the meetings. In order to use the custom template, you need to create a template for which you can follow these guide. Once you have setup the template, you can use the REST API to start the livestream with the
templateURL
parameter.
-
Sign up on VideoSDK and visit API Keys section to get your API key and Secret key.
-
Get familiarized with API key and Secret key.
-
Get familiarized with Token.
- Development environment requirements:
- Java Development Kit
- Android Studio 3.0 or later
- A physical or virtual mobile device running Android 5.0 or later
- Valid Video SDK Account
Clone the repository to your local environment.
git clone https://github.com/videosdk-live/videosdk-hls-android-java-example.git
Generate temporary token from Video SDK Account.
auth_token = "TEMPORARY-TOKEN";
Run the android app with Shift+F10 or the ▶ Run from toolbar.
-
Meeting
- A Meeting represents Real time audio and video communication.Note : Don't confuse with Room and Meeting keyword, both are same thing 😃
-
Sessions
- A particular duration you spend in a given meeting is a referred as session, you can have multiple session of a particular meetingId. -
Participant
- Participant represents someone who is attending the meeting's session,local partcipant
represents self (You), for this self, other participants areremote participants
. -
Stream
- Stream means video or audio media content that is either published bylocal participant
orremote participants
. -
Mode
- There are 2 types of modes:CONFERENCE
: Both audio and video streams will be produced and consumed in this mode.VIEWER
: Audio and video streams will not be produced or consumed in this mode.
Add all the following permissions to AndroidManifest.xml file.
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
Token is used to create and validate a meeting using API and also initialise a meeting.
🛠️ Development Environment
:
- For development, you can use temporary token. Visit VideoSDK dashboard to generate temporary token.
🌐 Production Environment
:
- For production, you have to set up an authentication server to authorize users. Follow our official example repositories to setup authentication server, videosdk-rtc-api-server-examples
create meeting
- Please refer this documentation to create meeting.validate meeting
- Please refer this documentation to validate the meetingId.
- For meeting initialization, you have to first initialize the
VideoSDK
. You can initialize theVideoSDK
usinginitialize()
method.
VideoSDK.initialize(Context context)
- After successfully initialization, you can configure
VideoSDK
by passing token inconfig
method
VideoSDK.config(String token)
- After VideoSDK initialization and configuration, you can initialize the meeting using
initMeeting()
method.initMeeting()
will generate a newMeeting
class and the initiated meeting will be returned.
Meeting meeting = VideoSDK.initMeeting(
Context context,
String meetingId,
String name,
boolean micEnabled,
boolean webcamEnabled,
String participantId,
String mode,
Map<String, CustomStreamTrack> customTracks)
meeting.join();
// Only one participant will leave/exit the meeting; the rest of the participants will remain.
meeting.leave();
// The meeting will come to an end for each and every participant. So, use this function in accordance with your requirements.
meeting.end();
- If you want to change the mode of a participant, use the meeting's
changeMode()
method.
meeting.changeMode(String mode)
By implementing MeetingEventListener
, VideoSDK sends callbacks to the client app whenever there is a change or update in the meeting after a user joins.
MeetingEventListener meetingEventListener = new MeetingEventListener() {
@Override
public void onMeetingJoined() {
// This event will be emitted when a localParticipant(you) successfully joined the meeting.
}
@Override
public void onMeetingLeft() {
// This event will be emitted when a localParticipant(you) left the meeting.
}
@Override
public void onParticipantJoined(Participant participant) {
// This event will be emitted when a new participant joined the meeting.
// [participant]: new participant who joined the meeting
}
@Override
public void onParticipantLeft(Participant participant) {
// This event will be emitted when a joined participant left the meeting.
// [participant]: participant who left the meeting
}
@Override
public void onHlsStateChanged(JSONObject HlsState) {
// This event will be emitted whenever meeting HLS state changes.
// [HlsState] : state of HLS
}
@Override
public void onParticipantModeChanged(JSONObject data) {
// This event will be emitted when any partcipant's mode changed.
// [data] : { mode: String, participantId: String }
}
@Override
public void onPresenterChanged(String participantId) {
// This event will be emitted when any participant starts or stops screen sharing.
// [participantId]: Id of participant who shares the screen.
}
@Override
public void onSpeakerChanged(String participantId) {
// This event will be emitted when a active speaker changed.
// [participantId] : Id of active speaker
}
@Override
public void onRecordingStateChanged(String recordingState) {
// This event will be emitted whenever meeting recording state changes.
// [recordingState] : state of meeting recording
}
};
-
onHlsStateChanged - Whenever meeting HLS state changes, then
onHlsStateChanged
event will trigger. -
You can get the
playbackHlsUrl
andlivestreamUrl
of the HLS to play it on the Viewer side when the state changes toHLS_PLAYABLE
.
private final MeetingEventListener meetingEventListener = new MeetingEventListener() {
@Override
public void onHlsStateChanged(JSONObject HlsState) {
switch (HlsState.getString("status")) {
case "HLS_STARTING":
Log.d("onHlsStateChanged", "Meeting hls is starting");
break;
case "HLS_STARTED":
Log.d("onHlsStateChanged", "Meeting hls is started");
break;
case "HLS_PLAYABLE":
Log.d("onHlsStateChanged", "Meeting hls is playable now");
// on hls playable you will receive playbackHlsUrl
String playbackHlsUrl = HlsState.getString("playbackHlsUrl");
break;
case "HLS_STOPPING":
Log.d("onHlsStateChanged", "Meeting hls is stopping");
break;
case "HLS_STOPPED":
Log.d("onHlsStateChanged", "Meeting hls is stopped");
break;
}
}
}
// unmute mic
meeting.unmuteMic();
// mute mic
meeting.muteMic();
- The
meeting.getMics()
function allows a participant to list all of the attached microphones (e.g., Bluetooth and Earphone).
// get connected mics
Set<AppRTCAudioManager.AudioDevice> mics = meeting.getMics();
- Local participant can change the audio device using
changeMic(AppRTCAudioManager.AudioDevice device)
method ofmeeting
class.
// change mic
meeting.changeMic(AppRTCAudioManager.AudioDevice device);
Please consult our documentation Change Audio Device for more infromation.
// enable webcam
meeting.enableWebcam();
// disable webcam
meeting.disableWebcam();
// switch webcam
meeting.changeWebcam();
// start HLS
meeting.startHls(JSONObject config);
// stop HLS
meeting.stopHls();
// pin local participant
meeting.getLocalParticipant().pin(String type);
// unpin local participant
meeting.getLocalParticipant().unpin(String type);
By implementing ParticipantEventListener
, VideoSDK sends callbacks to the client app whenever a participant's video, audio, or screen share stream is enabled or disabled.
ParticipantEventListener participantEventListener = new ParticipantEventListener() {
@Override
public void onStreamEnabled(Stream stream) {
// This event will be triggered whenever a participant's video, audio or screen share stream is enabled.
}
@Override
public void onStreamDisabled(Stream stream) {
// This event will be triggered whenever a participant's video, audio or screen share stream is disabled.
}
};
If you want to learn more about, read the complete documentation of Android VideoSDK
- Here, we're using
ExoPlayer
to show the viewer interactive live streaming. Click here to know more aboutExoPlayer
.
We have 3 packages :
common
- common package includes all classes/files that are used in both mode.speakerMode
- speakerMode package includes all classes/files related toCONFERENCE
mode(speaker).viewerMode
- viewerMode package inclues all the classes/files related toVIEWER
mode.
common
└── meeting
└── reactions
1. Create or Join Meeting
common
└── meeting
└── activity
└── CreateOrJoinActivity.java
└── MainActivity.java
└── fragment
└── CreateOrJoinFragment.java
└── CreateMeetingFragment.java
└── JoinMeetingFragment.java
CreateOrJoinActivity.java
andactivity_create_or_join.xml
- This activity is used to ask permissions to the partcipant,and to initiate webcam and mic status.
CreateOrJoinFragment
,CreateMeetingFragment
,JoinMeetingFragment
will be bound to this activity.
CreateOrJoinFragment.java
andfragment_create_or_join.xml
- This fragment will includeCreate meeting Button
- This button will call api for create a new meeting and navigate toCreateMeetingFragment
.Join as speaker Button
- This button will navigate toJoinMeetingFragment
.Join as viewer Button
- This button will navigate toJoinMeetingFragment
.
CreateMeetingFragment.java
andfragment_create_meeting.xml
- This fragement will includeTextView for MeetingId
- This textView will contain meeting Id.EditText for ParticipantName
- This edit text will contain name of the participant.Create Meeting Button
- This button will navigate toMainActivity
.
JoinMeetingFragment.java
andfragment_join_meeting.xml
- This fragement will includeEditText for MeetingId
- This edit text will contain the meeting Id that you want to join.EditText for ParticipantName
- This edit text will contain name of the participant.Join Meeting Button
- This button will call api for join meeting with meetingId that you provided and navigate toMainActivity
.
MainActivity.java
- This activity is used to initialize the meeting and navigate toMainFragemnt
orViewerFragment
according to user choice.
2. Live Reactions
common
└── reactions
└── DirectionGenerator.java
└── OverTheTopLayer.java
└── ZeroGravityAnimation.java
DirectionGenerator.java
class,OverTheTopLayer.java
class andZeroGravityAnimation.java
files used to show Live Reactions.
Viewer Host
speakerMode
└── manageTabs
└── SpeakerFragment.java
└── TabAdapter.java
└── stage
└── StageFragment.java
└── participantList
└── ParticipantListAdapter.java
└── ParticipantListFragment.java
1. Manage Tabs
SpeakerFragment.java
&TabAdapter.java
files used to manage tabs.
2. Stage
StageFragment.java
fragment is stage for speaker where he/she controlls meeting.
-
Audio & Video Settings
settings_layout.xml
file used to show Audio & Video Settings.
3. Participants
-
ParticipantListAdapter.java
,ParticipantListFragment.java
,fragment_participant.xml
anditem_participant_list_layout.xml
files used to show Participants. -
Add as a co-Host
- Here, we are using
pubSub
to request a viewer to be co-host. Click here to know more aboutpubSub
.
Host Viewer
- Here, we are using
viewerMode
└── ViewerFragment.java
└── TrackSelectionDialog.java
└── productsAdapter.java
1. ViewerFragment
ViewerFragment.java
fragment is main fragment for viewer mode.
2. TrackSelectionDialog
TrackSelectionDialog.java
,track_selection_dialog.xml
files used to set quality of media (video).
3. AddToCart
ProductsAdapter.java
,products_layout.xml
,item_products.xml
file used to show list of products.- Its is optional to show,useful for E-commerce app.
- videosdk-rtc-prebuilt-examples
- videosdk-rtc-javascript-sdk-example
- videosdk-rtc-react-sdk-examplee
- videosdk-rtc-react-native-sdk-example
- videosdk-rtc-flutter-sdk-example
- videosdk-rtc-android-java-sdk-example
- videosdk-rtc-android-kotlin-sdk-example
- videosdk-rtc-ios-sdk-example
- videosdk-hls-react-sdk-example
- videosdk-hls-react-native-sdk-example
- videosdk-hls-flutter-sdk-example
- videosdk-hls-android-java-example
- videosdk-hls-android-kotlin-example
Read the documentation to start using Video SDK.