In the next step you'll learn more about events and listeners in Events Basics guide.
StormPlayer is a complete video player for Storm Server Server. It's based on the ExoPlayer library. You can modify it according to your preferences.
MainActivity.java file
StormLibrary stormLibrary = new StormLibrary();
StormPlayerView stormPlayerView = findViewById(R.id.stormPlayerView);
stormPlayerView.setStormLibrary(stormLibrary);
StormMediaItem stormMediaItem = new StormMediaItem("stormserver.myhost.com",443,true,"live","my_stream_320","320p");
stormLibrary.addMediaItem(stormMediaItem);
stormMediaItem = new StormMediaItem("stormserver.myhost.com",443,true,"live","my_stream_720","720p");
stormLibrary.addMediaItem(stormMediaItem, true);
try{
stormLibrary.prepare(true);
}catch(Exception e){
e.printStackTrace();
}
activity_main.xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.stormstreaming.stormplayer.StormPlayerView
android:id="@+id/stormPlayerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,16:9"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.stormstreaming.stormplayer.StormPlayerView
android:id="@+id/stormPlayerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,16:9"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
ExoPlayer library view implementation
StormLibrary stormLibrary = new StormLibrary();
Here we create a new StormLibrary object. This object is responsible for downloading a stream from the Storm server and for all actions such as play, pause, stop, seek.
StormPlayerView stormPlayerView = findViewById(R.id.stormPlayerView);
stormPlayerView.setStormLibrary(stormLibrary);
The Storm Android Library instance is being attached to the Storm Android Player
StormMediaItem stormMediaItem = new StormMediaItem("stormserver.myhost.com",443,true,"live","my_stream_320","320p");
stormLibrary.addMediaItem(stormMediaItem);
New StormMediaItem object containing information about the stream is created. Then it is added to Storm Library on the StormLibrary object. If you wish to learn more about StormMediaItem or use Gateway server approach please check our Media management section of this library.
stormMediaItem = new StormMediaItem("stormserver.myhost.com",443,true,"live","my_stream_720","720p");
stormLibrary.addMediaItem(stormMediaItem, true);
If the player is to support multiple qualities, we can add any number of StormMediaItem objects. Thanks to this approach, we will be able to create a video quality selection button and freely switch between objects.
try {
stormLibrary.prepare(true);
} catch(Exception e){
e.printStackTrace();
}
The prepare() method is responsible for preparing the library to run. Its parameter is the boolean autostart field, which tells you whether the player should start playing immediately or wait for the play button to be pressed.
To avoid the effect of double video playback after rotating the device, a <activity> tag in the AndroidManifest.xml file should include parameter android:configChanges="orientation|screenSize":
android:configChanges="orientation|screenSize"
Create a free ticket and our support team will provide you necessary assistance.