Search code examples
android-layoutandroid-activitywowzalibstreaming

Play audio automatically on load of VideoView using Libstreaming library (Android)


I am developing a phonegap application which has a VideoView screen to play audio (Coming from Wowza streaming engine). My issue is that, I want to play audio instantly when VideoView gets loaded on the screen. What currently is happening in my app, When my VideoView gets loaded It does not even show up on the screen (It shows up when I touch the screen, This is another issue).

Now when it appears on the screen on touch, I have to click on the play button to start playing the audio. (I am using libstreaming library)

Here is my code-

activity_main.xml

<io.vov.vitamio.widget.VideoView
    android:id="@+id/video_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    android:visibility="visible"
    />

Activity Class:

private VideoView mVideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_main);

    if (!LibsChecker.checkVitamioLibs(this))
        return;

    mVideoView = (VideoView) findViewById(R.id.video_view);
    mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
    mVideoView.getHolder().setFormat(PixelFormat.RGBX_8888);
    startRtmpStream();
}

public void startRtmpStream() {
    mVideoView.setVideoPath(AppConfig.STREAM_URL_AUDIO_ONLY);
    mVideoView.setMediaController(new MediaController(this));
    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mediaPlayer) {
            mediaPlayer.setPlaybackSpeed(1.0f);
        }
    });
    mVideoView.start();
}

AppConfig.java

public class AppConfig {
     public static final String STREAM_URL_AUDIO_ONLY = "rtmp://10.101.3.129:1935/app1/myStream";
     public static final String PUBLISHER_USERNAME = "";
     public static final String PUBLISHER_PASSWORD = "";}

Solution

  • This is how I solved it.

    Actually Vitamio media player starts playing audio automatically If the Incoming stream tab of respective app on Wowza media server is containing the audio in running mode.

    I mean, call Vitamio's start() method only when Audio is up and running on Wowza media server.

    What I did is, I am firstly checking (in every 5 seconds) whether audio is up and running on Wowza (gets audio stream from another device) or not, If it's running then call start() method.

    Check this link

    The problem occurs when audio on Wowza server is not running and Vitamio start() method gets executed. You will have to implement a RestAPI web service to check audio on Wowza in some time interval.