wowza云直播流不通

时间:2017-09-12 11:46:46

标签: android wowza wowza-transcoder

我使用Wowza流媒体云它可以正常使用网络上的HLS链接,但是一个没有在网络上工作的Android设备。任何人都知道它是如何工作的。

并且rtsp实时链接也无法在Android设备上运行

公共类AnotherOne扩展了AppCompatActivity实现         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 个答案:

答案 0 :(得分:0)

你需要声明一个视图来渲染视频View和 您需要使用Android提供的Media Player Api来传输m3u8.it非常简单,播放实时内容请遵循此代码。

   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;
    }
  }

}

让我知道它是否有帮助。