wowza cloud live streaming is not working

246 views Asked by At

I'm using Wowza streaming cloud it works fine using HLS link on the web but an android device not working on the web view.can you anyone me how its work.

And rtsp live link also not working on android device

public class AnotherOne extends AppCompatActivity implements SurfaceHolder.Callback, MediaPlayer.OnPreparedListener{

private String Downloadurl;
private int playminute;
private SurfaceView mSurfaceView;
private MediaPlayer mMediaPlayer;
private SurfaceHolder mSurfaceHolder;
ProgressBar p_bar;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_another_one);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    View decorView = getWindow().getDecorView();

    int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);


    Downloadurl = "https://7c6ad8.entrypoint.cloud.wowza.com/app-04be/ngrp:f23a3900_all/playlist.m3u8";
    // Description =  getIntent().getStringExtra("Description");
    Log.e("kanish","Download Url inside player:"+Downloadurl);
    mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView);
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
   // p_bar.setVisibility(View.VISIBLE);
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setDisplay(mSurfaceHolder);
    try {
        mMediaPlayer.setDataSource(Downloadurl);
        mMediaPlayer.prepare();
        mMediaPlayer.setOnPreparedListener(AnotherOne.this);
        //mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}

@Override
public void onBackPressed() {
    super.onBackPressed();

}

@Override
public void onPrepared(MediaPlayer mp) {
    //p_bar.setVisibility(View.GONE);
    mMediaPlayer.start();
}

@Override
protected void onPause() {
    super.onPause();
    releaseMediaPlayer();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    releaseMediaPlayer();
}

private void releaseMediaPlayer() {
    if (mMediaPlayer != null) {
        mMediaPlayer.release();
        mMediaPlayer = null;
    }
}

}

1

There are 1 answers

6
DevKRos On BEST ANSWER

you need to declare a view to render video View and You need to use Media Player Api Provided by Android to Stream m3u8.it is pretty Simple to play Live content follow this code.

   public class PlayerActivity extends AppCompatActivity implements 
   SurfaceHolder.Callback, MediaPlayer.OnPreparedListener {


   private String Downloadurl;
   private int playminute;
   private SurfaceView mSurfaceView;
   private MediaPlayer mMediaPlayer;
   private SurfaceHolder mSurfaceHolder;
   ProgressBar p_bar;

    @Override
   protected void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);
    setContentView(R.layout.player);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
     View decorView = getWindow().getDecorView();

    int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);


    Downloadurl = "YOUR M3U8 URL";
    // Description =  getIntent().getStringExtra("Description");
       Log.e("kanish","Download Url inside player:"+Downloadurl);
    mSurfaceView = (SurfaceView) findViewById(R.id.surface_view);
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(PlayerActivity.this);
    }

     @Override
     public void surfaceCreated(SurfaceHolder holder) {
    p_bar.setVisibility(View.VISIBLE);
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setDisplay(mSurfaceHolder);
    try {
        mMediaPlayer.setDataSource(Downloadurl);
        mMediaPlayer.prepare();
        mMediaPlayer.setOnPreparedListener(PlayerActivity.this);
        //mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      } catch (IOException e) {
        e.printStackTrace();
      }
   }

   @Override
   public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
   }

   @Override
   public void surfaceDestroyed(SurfaceHolder holder) {
   }

   @Override
   public void onBackPressed() {
    super.onBackPressed();

    }

   @Override
   public void onPrepared(MediaPlayer mp) {
    p_bar.setVisibility(View.GONE);
    mMediaPlayer.start();
    }

   @Override
   protected void onPause() {
      super.onPause();
       releaseMediaPlayer();
      }

    @Override
    protected void onDestroy() {
    super.onDestroy();
    releaseMediaPlayer();
     }

   private void releaseMediaPlayer() {
      if (mMediaPlayer != null) {
        mMediaPlayer.release();
        mMediaPlayer = null;
    }
  }

}

Let me Know if it helps.