Skip to content

Commit

Permalink
Merge pull request #83 from ksvc/v3.0.0-28654
Browse files Browse the repository at this point in the history
update to v3.0.0-28654
  • Loading branch information
chriszeng87 authored Jan 24, 2018
2 parents dc6f170 + cf32352 commit 8336553
Show file tree
Hide file tree
Showing 114 changed files with 10,156 additions and 92 deletions.
4 changes: 4 additions & 0 deletions KSYLiveDemo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboardHidden|screenSize"
/>
<activity android:name=".player.activity.MultiplePlayerActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboardHidden|screenSize"
/>
<activity android:name=".player.activity.PlayerActivity"
android:screenOrientation="portrait"></activity>

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(HistoryActivity.this, FloatingVideoActivity.class);
intent.putExtra("path", path);
startActivity(intent);
}else {
} else if (playerType.equals(Settings.MULTIPLE_PLAYER)){
Intent intent = new Intent(HistoryActivity.this, MultiplePlayerActivity.class);
intent.putExtra("path", path);
startActivity(intent);
} else {
Intent intent = new Intent(HistoryActivity.this, PlayRecordActivity.class);
intent.putExtra("path", path);
startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
package com.ksyun.live.demo.player.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.TextView;

import com.ksyun.live.demo.R;
import com.ksyun.media.player.IMediaPlayer;
import com.ksyun.media.player.KSYMediaPlayer;

import java.io.IOException;

/**
* Created by xbc on 2017/12/29.
*/

public class MultiplePlayerActivity extends Activity {

private SurfaceView mMasterSurfaceView;
private SurfaceView mSlaveSurfaceView;
private SurfaceView mSlaveSurfaceView2;
private TextView mMaster;
private TextView mSlave;

private KSYMediaPlayer mMasterPlayer;
private KSYMediaPlayer mSlavePlayer;
private KSYMediaPlayer mSlavePlayer2;
private String mDataSource;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_multiple_player);

mMasterSurfaceView = (SurfaceView) findViewById(R.id.player_master);
mSlaveSurfaceView = (SurfaceView) findViewById(R.id.player_slave);
mSlaveSurfaceView2 = (SurfaceView) findViewById(R.id.player_slave2);
mMaster = (TextView) findViewById(R.id.control_master);
mSlave = (TextView) findViewById(R.id.control_slave);
mDataSource = getIntent().getStringExtra("path");
initPlayers();
initViews();
}

@Override
protected void onDestroy() {
super.onDestroy();
if (mSlavePlayer2 != null)
mSlavePlayer2.release();
mSlavePlayer2 = null;

if (mSlavePlayer != null)
mSlavePlayer.release();
mSlavePlayer = null;

if (mMasterPlayer != null)
mMasterPlayer.release();
mMasterPlayer = null;
}

private void initPlayers() {
mMasterPlayer = new KSYMediaPlayer.Builder(this).build();
mSlavePlayer = new KSYMediaPlayer.Builder(this).build();
mSlavePlayer2 = new KSYMediaPlayer.Builder(this).build();


mMasterPlayer.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(IMediaPlayer mp) {
if (mMasterPlayer != null)
mMasterPlayer.start();
}
});
try {
mMasterPlayer.shouldAutoPlay(false);
mMasterPlayer.setDataSource(mDataSource);
mMasterPlayer.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}

mSlavePlayer.shouldAutoPlay(false);
mSlavePlayer.addMasterClock(mMasterPlayer);
mSlavePlayer.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(IMediaPlayer mp) {
if (mSlavePlayer != null) {
mSlavePlayer.start();
mSlavePlayer.setPlayerMute(1);
}
}
});
try {
mSlavePlayer.setDataSource(mDataSource);
mSlavePlayer.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}

mSlavePlayer2.shouldAutoPlay(false);
mSlavePlayer2.addMasterClock(mMasterPlayer);
mSlavePlayer2.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(IMediaPlayer mp) {
if (mMasterPlayer != null)
mMasterPlayer.start();
if (mSlavePlayer != null) {
mSlavePlayer.start();
mSlavePlayer.setPlayerMute(1);
}
if (mSlavePlayer2 != null) {
mSlavePlayer2.start();
mSlavePlayer2.setPlayerMute(1);
}
}
});
try {
mSlavePlayer2.setDataSource(mDataSource);
mSlavePlayer2.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}
}

private boolean mMasterPlaying = true;
private boolean mSlavePlaying = true;
private void initViews() {
mMaster.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mMasterPlaying)
mMasterPlayer.pause();
else
mMasterPlayer.start();

mMasterPlaying = !mMasterPlaying;
}
});

mSlave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mSlavePlaying)
mSlavePlayer.pause();
else
mSlavePlayer.start();

mSlavePlaying = !mSlavePlaying;
}
});

mMasterSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {

}

@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
if (mMasterPlayer != null)
mMasterPlayer.setSurface(surfaceHolder.getSurface());
}

@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
if (mMasterPlayer != null)
mMasterPlayer.setSurface(null);
}
});

mSlaveSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {

}

@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
if (mSlavePlayer != null)
mSlavePlayer.setSurface(surfaceHolder.getSurface());
}

@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
if (mSlavePlayer != null)
mSlavePlayer.setSurface(null);
}
});

mSlaveSurfaceView2.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {

}

@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
if (mSlavePlayer2 != null)
mSlavePlayer2.setSurface(surfaceHolder.getSurface());
}

@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
if (mSlavePlayer2 != null)
mSlavePlayer2.setSurface(null);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public void onClick(View view) {
Intent intent = new Intent(NetMediaActivty.this, FloatingVideoActivity.class);
intent.putExtra("path", path);
startActivity(intent);
} else {
} else if (playerType.equals(Settings.MULTIPLE_PLAYER)){
Intent intent = new Intent(NetMediaActivty.this, MultiplePlayerActivity.class);
intent.putExtra("path", path);
startActivity(intent);
}else {
Intent intent = new Intent(NetMediaActivty.this, PlayRecordActivity.class);
intent.putExtra("path", path);
startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SettingActivity extends AppCompatActivity implements RadioGroup.OnC
private RadioButton radioFloating;
private RadioButton radioRecord;
private Switch debugSwitch;

private RadioButton radioMultiplePlayer;
// private Spinner mSpinner;

private RadioGroup mChooseCodec;
Expand Down Expand Up @@ -129,7 +129,7 @@ private void initSetting(String chooseDecode, String chooseDebug, String bufferS
radioVod = (RadioButton) findViewById(R.id.type_vod);
radioFloating = (RadioButton) findViewById(R.id.type_floating);
radioRecord = (RadioButton) findViewById(R.id.type_record);

radioMultiplePlayer = (RadioButton) findViewById(R.id.type_multiple_player);
mBufferSize.setText(bufferSize);
mBufferTime.setText(bufferTime);

Expand Down Expand Up @@ -171,6 +171,9 @@ private void initSetting(String chooseDecode, String chooseDebug, String bufferS
case Settings.RECORD:
mChooseType.check(radioRecord.getId());
break;
case Settings.MULTIPLE_PLAYER:
mChooseType.check(radioMultiplePlayer.getId());
break;
default:
mChooseType.check(radioLive.getId());
editor.putString("choose_type", Settings.LIVE);
Expand Down Expand Up @@ -201,6 +204,9 @@ public void onCheckedChanged(RadioGroup radioGroup, int i) {
case R.id.type_record:
editor.putString("choose_type", Settings.RECORD);
break;
case R.id.type_multiple_player:
editor.putString("choose_type", Settings.MULTIPLE_PLAYER);
break;
default:
break;
}
Expand Down
Loading

0 comments on commit 8336553

Please sign in to comment.