Skip to content

Commit

Permalink
有问题.....
Browse files Browse the repository at this point in the history
  • Loading branch information
yetote committed Aug 30, 2019
1 parent 44bce7e commit bb7b8fe
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 89 deletions.
4 changes: 2 additions & 2 deletions app/src/main/cpp/audio/AudioPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ AudioPlay::onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFra

int betterSize = numFrames * 4;
if (!canPlay) {
LOGE(AudioPlay_TAG, "%s:准备未完成", __func__);
// LOGE(AudioPlay_TAG, "%s:准备未完成", __func__);
return DataCallbackResult::Continue;
}
if (playStates.isStop()) {
Expand Down Expand Up @@ -189,7 +189,7 @@ void AudioPlay::popData() {
if (ringArray != nullptr) {
ringArray->write(outBuffer, bufferSize);
}
LOGE(AudioPlay_TAG,"%s:解码成功",__func__);
// LOGE(AudioPlay_TAG,"%s:解码成功",__func__);
} else {
LOGE(AudioPlay_TAG, "%s:解码出错%s", __func__, av_err2str(rst));
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/cpp/decode/Decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void Decode::decode() {
}
std::lock_guard<std::mutex> guard(mutex);
rst = av_read_frame(pFmtCtx, packet);
LOGE(Decode_TAG, "%s:开始分包", __func__);
// LOGE(Decode_TAG, "%s:开始分包", __func__);
if (rst < 0) {
switch (rst) {
case AVERROR_EOF:
Expand All @@ -222,13 +222,13 @@ void Decode::decode() {
if (packet->stream_index == audioIndex) {
if (audioPlayer != nullptr) {
audioPlayer->pushData(packet);
LOGE(Decode_TAG, "%s:音频入队", __func__);
// LOGE(Decode_TAG, "%s:音频入队", __func__);
continue;
}
} else if (packet->stream_index == videoIndex) {
if (videoPlayer != nullptr) {
videoPlayer->pushData(packet);
LOGE(Decode_TAG, "%s:视频入队", __func__);
// LOGE(Decode_TAG, "%s:视频入队", __func__);
continue;
}
}
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/cpp/video/VideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void VideoPlayer::decode() {
AVFrame *pFrame = av_frame_alloc();
AVPacket *dataPacket = av_packet_alloc();
while (!playStates.isEof() && !playStates.isStop()) {
LOGE(VideoPlayer_TAG, "%s:开始解码", __func__);
// LOGE(VideoPlayer_TAG, "%s:开始解码", __func__);
if (playStates.isPause()) {
usleep(300);
continue;
Expand Down Expand Up @@ -267,8 +267,7 @@ void VideoPlayer::decode() {
av_free(pFrame420P);
av_free(buffer);
pFrame420P = nullptr;

LOGE(VideoPlayer_TAG, "line in 144:解码成功");
// LOGE(VideoPlayer_TAG, "line in 144:解码成功");
}
}
} else {
Expand Down Expand Up @@ -307,7 +306,7 @@ void VideoPlayer::clear() {

void VideoPlayer::stop() {
std::lock_guard<std::mutex> guard(mutex);
LOGE(VideoPlayer_TAG,"%s:开始释放",__func__);
LOGE(VideoPlayer_TAG, "%s:开始释放", __func__);
while (!videoData.empty()) {
AVPacket *packet = videoData.front();
av_packet_free(&packet);
Expand Down
42 changes: 5 additions & 37 deletions app/src/main/java/com/yetote/bamboomusic/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import static android.widget.ListPopupWindow.MATCH_PARENT;
import static android.widget.ListPopupWindow.WRAP_CONTENT;
import static com.yetote.bamboomusic.media.MusicService.SERVICE_IN_MAIN_ACTIVITY;
import static com.yetote.bamboomusic.media.MusicService.STATE_PAUSE;
import static com.yetote.bamboomusic.media.MusicService.STATE_PLAYING;
import static com.yetote.bamboomusic.media.MusicService.STATE_PREPARE;
Expand Down Expand Up @@ -129,42 +130,6 @@ public void onStopTrackingTouch(SeekBar seekBar) {
}

private void callBack() {
// musicBinder.setServiceFFmpegCallBack(new OnFFmpegCallback() {
// @Override
// public void onPrepare(boolean prepare, int totalTime) {
// musicProgressButton.changeState(MusicProgressButton.STATE_PROGRESS);
// musicDetailsPopTotalTime.setText(TextUtil.time2err(totalTime));
// musicDetailsPopProgress.setMax(totalTime);
// musicProgressButton.setTotalTime(totalTime);
// musicBinder.play();
// }
//
// @Override
// public void onPlaying(int currentTime) {
// musicDetailsPopProgress.setProgress(currentTime);
// if (musicProgressButton.getPlayState() != MusicProgressButton.STATE_PLAYING) {
// musicProgressButton.changeState(MusicProgressButton.STATE_PLAYING);
// }
// musicProgressButton.showPlayingAnimation(currentTime);
// musicDetailsPopCurrentTime.setText(TextUtil.time2err(currentTime));
// musicDetailsPopPlayController.setBackground(getDrawable(R.drawable.music_state_pause));
// }
//
// @Override
// public void onPause() {
// musicProgressButton.changeState(MusicProgressButton.STATE_STOP);
// }
//
// @Override
// public void onResume() {
//
// }
//
// @Override
// public void onStop() {
// musicProgressButton.changeState(MusicProgressButton.STATE_STOP);
// }
// });
musicBinder.setServiceFFmpegCallBack(this);
}

Expand Down Expand Up @@ -212,9 +177,12 @@ public void onClick(View v) {
break;
case R.id.main_musicProgress_btn:
if (musicBinder != null) {
if (musicBinder.getServiceFFmpegCallBack() == null) {

if (musicBinder.getLocal() != SERVICE_IN_MAIN_ACTIVITY) {
musicBinder.setServiceFFmpegCallBack(null);
musicBinder.setServiceFFmpegCallBack(this);
}

switch (musicBinder.getState()) {
case STATE_STOP:
musicBinder.prepare(musicList.get(playingPos));
Expand Down
89 changes: 46 additions & 43 deletions app/src/main/java/com/yetote/bamboomusic/adapter/FoundAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;

import static android.content.Context.BIND_AUTO_CREATE;
import static com.yetote.bamboomusic.media.MusicService.SERVICE_IN_FRAGMENT;
import static com.yetote.bamboomusic.media.MusicService.STATE_STOP;

/**
Expand All @@ -39,7 +40,7 @@
* @chang time
* @class describe
*/
public class FoundAdapter extends RecyclerView.Adapter {
public class FoundAdapter extends RecyclerView.Adapter implements OnFFmpegCallback {
private ArrayList<FoundModel> list;
private Context context;
public static final int PATH_TAG = 1;
Expand All @@ -56,43 +57,8 @@ public class FoundAdapter extends RecyclerView.Adapter {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {

if (musicBinder != null) {

}

musicBinder = (MusicService.MusicBinder) service;
musicBinder.setServiceFFmpegCallBack(new OnFFmpegCallback() {
@Override
public void onFFmpegPrepare(boolean prepare, int totalTime) {
// if (totalTime != 0) {
// seekBar.setMax(totalTime);
// }
if (prepare) {
musicBinder.play(surface, width, height);
isPlaying = true;
}
}

@Override
public void onFFmpegPlaying(int currentTime) {
// seekBar.setProgress(currentTime);
}

@Override
public void onFFmpegPause() {

}

@Override
public void onFFmpegResume() {

}

@Override
public void onFFmpegStop() {

}
});
callBack();
}

@Override
Expand All @@ -101,6 +67,10 @@ public void onServiceDisconnected(ComponentName name) {
}
};

private void callBack() {
musicBinder.setServiceFFmpegCallBack(this);
}

public void setItemClickListener(RecyclerViewItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
Expand All @@ -112,6 +82,37 @@ public FoundAdapter(ArrayList<FoundModel> list, Context context) {
context.bindService(musicService, serviceConnection, BIND_AUTO_CREATE);
}

@Override
public void onFFmpegPrepare(boolean prepare, int totalTime) {
if (prepare) {
musicBinder.play(surface, width, height);
isPlaying = true;
// if (totalTime != 0) {
// seekBar.setMax(totalTime);
// }
}
}

@Override
public void onFFmpegPlaying(int currentTime) {
// seekBar.setProgress(currentTime);
}

@Override
public void onFFmpegPause() {

}

@Override
public void onFFmpegResume() {

}

@Override
public void onFFmpegStop() {

}

class MyViewHolder extends RecyclerView.ViewHolder {
private SurfaceView surfaceView;
private TextView tag;
Expand Down Expand Up @@ -205,6 +206,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
// }
// });
// });

return new MyViewHolder(v);
}

Expand Down Expand Up @@ -241,6 +243,13 @@ public void surfaceDestroyed(SurfaceHolder holder) {
}
});
vh.getStart().setOnClickListener(v -> {
if (musicBinder != null) {
if (musicBinder.getLocal() != SERVICE_IN_FRAGMENT) {
musicBinder.stop();
musicBinder.setServiceFFmpegCallBack(null);
musicBinder.setServiceFFmpegCallBack(this);
}
}
int pos = position;
if (pos != playingPos) {
if (musicBinder.getState() != STATE_STOP) {
Expand Down Expand Up @@ -298,10 +307,4 @@ public void onStopTrackingTouch(SeekBar seekBar) {
public int getItemCount() {
return list.size();
}

@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);
// musicBinder.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class MusicService extends Service {
private Surface surface;
private int w, h;
private int type;
public static final int SERVICE_IN_MAIN_ACTIVITY = 0x0007;
public static final int SERVICE_IN_FRAGMENT = 0x0008;
public static int serviceLocal;

@Nullable
@Override
Expand Down Expand Up @@ -98,6 +101,10 @@ public int getState() {
return state;
}

public int getLocal() {
return serviceLocal;
}

private OnFFmpegCallback serviceFFmpegCallBack;

public OnFFmpegCallback getServiceFFmpegCallBack() {
Expand Down

0 comments on commit bb7b8fe

Please sign in to comment.