Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/3.5.0.204 #43

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Agora-Online-KTV-Android/KTV/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//Arogra SDK
implementation 'io.agora.rtc:full-sdk:3.5.1'
implementation 'com.github.agorabuilder:full-sdk:3.5.0.204.2'

implementation 'jp.wasabeef:glide-transformations:4.0.0'
implementation 'com.github.open-android:Glide-transformations:0.1.0'
implementation 'com.google.code.gson:gson:2.8.7'
implementation 'androidx.palette:palette:1.0.0'
api project(':data')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,27 @@
import java.util.Map;

import io.agora.ktv.bean.MemberMusicModel;
import io.agora.mediaplayer.IMediaPlayer;
import io.agora.mediaplayer.IMediaPlayerObserver;
import io.agora.rtc.Constants;
import io.agora.rtc.IRtcEngineEventHandler;
import io.agora.rtc.RtcEngine;
import io.agora.rtc.models.DataStreamConfig;

import static io.agora.mediaplayer.Constants.AudioDualMonoMode.AUDIO_DUAL_MONO_L;
import static io.agora.mediaplayer.Constants.AudioDualMonoMode.AUDIO_DUAL_MONO_R;
import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_FAILED;
import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_OPEN_COMPLETED;
import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_PAUSED;
import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_PLAYING;
import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_STOPPED;

public class MusicPlayer extends IRtcEngineEventHandler {
private Logger.Builder mLogger = XLog.tag("MusicPlayer");

private Context mContext;
private RtcEngine mRtcEngine;
private IMediaPlayer player;
private int mRole = Constants.CLIENT_ROLE_BROADCASTER;

private boolean mStopSyncLrc = true;
Expand Down Expand Up @@ -94,11 +105,11 @@ public void handleMessage(@NonNull Message msg) {
}
} else if (msg.what == ACTION_ON_MUSIC_OPENCOMPLETED) {
if (mCallback != null) {
mCallback.onMusicOpenCompleted((int) msg.obj);
mCallback.onMusicOpenCompleted(Long.valueOf((long) msg.obj).intValue());
}
} else if (msg.what == ACTION_ON_MUSIC_OPENERROR) {
if (mCallback != null) {
mCallback.onMusicOpenError((int) msg.obj);
mCallback.onMusicOpenError(Long.valueOf((long) msg.obj).intValue());
}
} else if (msg.what == ACTION_ON_MUSIC_PLAING) {
if (mCallback != null) {
Expand Down Expand Up @@ -128,7 +139,8 @@ public void handleMessage(@NonNull Message msg) {
public MusicPlayer(Context mContext, RtcEngine mRtcEngine) {
this.mContext = mContext;
this.mRtcEngine = mRtcEngine;

this.player = mRtcEngine.createMediaPlayer();
this.player.registerPlayerObserver(iMediaPlayerObserver);
reset();

mRtcEngine.addHandler(this);
Expand Down Expand Up @@ -197,7 +209,7 @@ public int open(@NonNull MemberMusicModel mMusicModel) {
MusicPlayer.mMusicModel = mMusicModel;
mLogger.i("play() called with: mMusicModel = [%s]", mMusicModel);
onMusicOpening();
int ret = mRtcEngine.startAudioMixing(fileMusic.getAbsolutePath(), false, false, 1);
int ret = player.open(fileMusic.getAbsolutePath(), 0);
mLogger.i("play() called ret= %s", ret);
return 0;
}
Expand All @@ -212,23 +224,23 @@ public void stop() {
return;
}

mRtcEngine.stopAudioMixing();
player.stop();
}

private void pause() {
mLogger.i("pause() called");
if (!mStatus.isAtLeast(Status.Started))
return;

mRtcEngine.pauseAudioMixing();
player.pause();
}

private void resume() {
mLogger.i("resume() called");
if (!mStatus.isAtLeast(Status.Started))
return;

mRtcEngine.resumeAudioMixing();
player.resume();
}

public void togglePlay() {
Expand All @@ -250,18 +262,18 @@ public void selectAudioTrack(int i) {
mAudioTrackIndex = i;

if (mMusicModel.getType() == MemberMusicModel.Type.Default) {
mRtcEngine.selectAudioTrack(mAudioTrackIndex);
player.selectAudioTrack(mAudioTrackIndex);
} else {
if (mAudioTrackIndex == 0) {
mRtcEngine.setAudioMixingDualMonoMode(Constants.AudioMixingDualMonoMode.getValue(Constants.AudioMixingDualMonoMode.AUDIO_MIXING_DUAL_MONO_L));
player.setAudioDualMonoMode(AUDIO_DUAL_MONO_L);
} else {
mRtcEngine.setAudioMixingDualMonoMode(Constants.AudioMixingDualMonoMode.getValue(Constants.AudioMixingDualMonoMode.AUDIO_MIXING_DUAL_MONO_R));
player.setAudioDualMonoMode(AUDIO_DUAL_MONO_R);
}
}
}

public void seek(long time) {
mRtcEngine.setAudioMixingPosition((int) time);
player.seek(time);
}

public boolean hasAccompaniment() {
Expand All @@ -277,7 +289,8 @@ public void toggleOrigle() {
}

public void setMusicVolume(int v) {
mRtcEngine.adjustAudioMixingVolume(v);
player.adjustPublishSignalVolume(v);
player.adjustPlayoutVolume(v);
}

public void setMicVolume(int v) {
Expand Down Expand Up @@ -340,7 +353,7 @@ public void run() {
mStopSyncLrc = false;
while (!mStopSyncLrc && mStatus.isAtLeast(Status.Started)) {
if (mStatus == Status.Started) {
mRecvedPlayPosition = mRtcEngine.getAudioMixingCurrentPosition();
mRecvedPlayPosition = player.getPlayPosition();
mLastRecvPlayPosTime = System.currentTimeMillis();

sendSyncLrc(lrcId, duration, mRecvedPlayPosition);
Expand Down Expand Up @@ -380,7 +393,7 @@ private void stopSyncLrc() {
}

private void startPublish() {
startSyncLrc(mMusicModel.getMusicId(), mRtcEngine.getAudioMixingDuration());
startSyncLrc(mMusicModel.getMusicId(), player.getDuration());
}

private void stopPublish() {
Expand All @@ -389,7 +402,6 @@ private void stopPublish() {

private void initAudioTracks() {
mAudioTrackIndex = 1;
// mAudioTracksCount = mRtcEngine.getAudioTrackCount();
mAudioTracksCount = 2;
}

Expand Down Expand Up @@ -432,25 +444,6 @@ protected void onReceivedSetLrcTime(int uid, long position) {
mLastRecvPlayPosTime = System.currentTimeMillis();
}

@Override
public void onAudioMixingStateChanged(int state, int errorCode) {
super.onAudioMixingStateChanged(state, errorCode);
mLogger.d("onAudioMixingStateChanged() called with: state = [%s], errorCode = [%s]", state, errorCode);
if (state == Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_PLAY) {
if (mStatus == Status.IDLE) {
onMusicOpenCompleted();
}
onMusicPlaing();
} else if (state == Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_PAUSED) {
onMusicPause();
} else if (state == Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_STOPPED) {
onMusicStop();
onMusicCompleted();
} else if (state == Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_ERROR) {
onMusicOpenError(errorCode);
}
}

private void onMusicOpening() {
mLogger.i("onMusicOpening() called");
mHandler.obtainMessage(ACTION_ONMUSIC_OPENING).sendToTarget();
Expand All @@ -463,7 +456,7 @@ private void onMusicOpenCompleted() {
initAudioTracks();

startDisplayLrc();
mHandler.obtainMessage(ACTION_ON_MUSIC_OPENCOMPLETED, mRtcEngine.getAudioMixingDuration()).sendToTarget();
mHandler.obtainMessage(ACTION_ON_MUSIC_OPENCOMPLETED, player.getDuration()).sendToTarget();
}

private void onMusicOpenError(int error) {
Expand Down Expand Up @@ -595,4 +588,61 @@ public interface Callback {
*/
void onMusicPositionChanged(long position);
}

private IMediaPlayerObserver iMediaPlayerObserver = new IMediaPlayerObserver() {
@Override
public void onPlayerStateChanged(io.agora.mediaplayer.Constants.MediaPlayerState state, io.agora.mediaplayer.Constants.MediaPlayerError error) {
mLogger.d("onPlayerStateChanged() called with: state = [%s], errorCode = [%s]", state, error);
if (state == PLAYER_STATE_PLAYING) {
if (mStatus == Status.IDLE) {
onMusicOpenCompleted();
}
onMusicPlaing();
} else if(state == PLAYER_STATE_OPEN_COMPLETED){
player.play();
} else if (state == PLAYER_STATE_PAUSED) {
onMusicPause();
} else if (state == PLAYER_STATE_STOPPED) {
onMusicStop();
onMusicCompleted();
} else if (state == PLAYER_STATE_FAILED) {
onMusicOpenError(error.ordinal());
}
}

@Override
public void onPositionChanged(long position) {

}

@Override
public void onPlayerEvent(io.agora.mediaplayer.Constants.MediaPlayerEvent eventCode, long elapsedTime, String message) {

}

@Override
public void onMetaData(io.agora.mediaplayer.Constants.MediaPlayerMetadataType type, byte[] data) {

}

@Override
public void onPlayBufferUpdated(long playCachedBuffer) {

}

@Override
public void onPreloadEvent(String src, io.agora.mediaplayer.Constants.MediaPlayerPreloadEvent event) {

}

@Override
public void onCompleted() {

}

@Override
public void onAgoraCDNTokenWillExpire() {

}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.concurrent.ConcurrentHashMap;

import io.agora.ktv.bean.MemberMusicModel;
import io.agora.mediaplayer.IMediaPlayer;
import io.agora.mediaplayer.IMediaPlayerObserver;
import io.agora.rtc.Constants;
import io.agora.rtc.IRtcEngineEventHandler;
import io.agora.rtc.RtcEngine;
Expand Down Expand Up @@ -154,12 +156,6 @@ private void iniRTC() {
config.mContext = mContext;
config.mAppId = appid;
config.mEventHandler = mIRtcEngineEventHandler;
// config.mChannelProfile = Constants.CHANNEL_PROFILE_LIVE_BROADCASTING;
// if (Config.isLeanCloud()) {
// config.mAreaCode = RtcEngineConfig.AreaCode.AREA_CODE_CN;
// } else {
// config.mAreaCode = RtcEngineConfig.AreaCode.AREA_CODE_GLOB;
// }

try {
mRtcEngine = RtcEngine.create(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected void iniData() {
Glide.with(this)
.asDrawable()
.load(mRoom.getCoverRes())
.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
.apply(RequestOptions.bitmapTransform(new BlurTransformation(this, 25, 3)))
.into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ protected void iniData() {
Glide.with(this)
.asDrawable()
.load(mRoom.getCoverRes())
.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
.apply(RequestOptions.bitmapTransform(new BlurTransformation(this, 25, 3)))
.into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
Expand Down
2 changes: 0 additions & 2 deletions Agora-Online-KTV-Android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ buildscript {
repositories {
google()
mavenCentral()
jcenter()
maven { url 'https://www.jitpack.io' }
}

Expand All @@ -27,7 +26,6 @@ allprojects {
repositories {
google()
mavenCentral()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
Expand Down
Loading