0
기본 Android 동영상 플레이어는 동영상 재생이 완료된 후 onCompletion 메소드를 호출하지 않습니다.Android 네이티브 미디어 플레이어가 실행되지 않음 완료 메소드
단일 비디오 또는 비디오 목록 (m3u8 파일)을 재생하는 활동이 있습니다. 동영상은 파일을 재생해야하므로 미디어 컨트롤러도 사용할 수 있지만 비디오가 끝나면 몇 초 후에 루프가 시작됩니다. 사용자가 미디어 컨트롤러에서 빨리 감기 옵션을 클릭하거나 두 번 탭하지 않으면 oncompletion 메서드가 활성화되지 않습니다.
비디오가 끝났을 때 onComplete 메서드를 자동으로 활성화하는 방법이 있습니까? (나는 청취자를 사용해 보았는데, 효과가 없다.) 내가 뭘 잘못했는지 지적한다.
public class VideoActivity extends ActionBarActivity implements MediaPlayer.OnCompletionListener {
private static final String TAG = VideoActivity.class.getSimpleName();
private VideoView mVideoViewStream1;
ProgressDialog mDialog;
private String mURL;
private ChannelPlaylist mChannelPlaylist;
private int mIndex;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
// Validate internet connection
if (!Util.isDeviceConnected(this)) {
FragmentManager fm = getSupportFragmentManager();
PopUpErrorFragment popupError = PopUpErrorFragment.newInstance(getString(R.string.errorInternetConnection));
popupError.show(fm, PopUpErrorFragment.TAG);
finish();
}
// Assign controls to their variable representations
mVideoViewStream1 = (VideoView) findViewById(R.id.vvVideo);
// Retrieve bundle data
Intent i = getIntent();
Bundle bundle = i.getExtras();
ChannelPlaylist channelPlaylist = bundle.getParcelable(KeyHelper.BUNDLE_CHANNEL_PLAYLIST);
if (channelPlaylist != null) {
this.mChannelPlaylist = channelPlaylist;
if (bundle.containsKey("index") && mIndex == 0) {
this.mIndex = bundle.getInt("index");
} else {
if (this.mIndex == 0) {
this.mIndex = this.mChannelPlaylist.getIndex();
}
}
this.mURL = this.mChannelPlaylist.getSchedule().get(mIndex).getStream_url();
} else {
this.mURL = bundle.getString("url");
}
progressDialog();
standardAndroidPlayer();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.video, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/***************************** CLASS METHODS **************************************************/
/**
* Dismissess the dialog
*/
private void dismissDialog() {
if (this.mDialog != null) {
mDialog.dismiss();
}
}
/**
* Standard android player
*/
private void standardAndroidPlayer() {
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(this);
mediacontroller.setAnchorView(mVideoViewStream1);
// Get the URL from String VideoURL
mVideoViewStream1.setMediaController(mediacontroller);
// Set media player completion listener
mVideoViewStream1.setOnCompletionListener(this);
mVideoViewStream1.setVideoURI(Uri.parse(this.mURL));
mVideoViewStream1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
//Log.i(TAG, "Duration = " + mVideoViewStream1.getDuration());
if (mp.isLooping()) mp.setLooping(false);
}
});
mVideoViewStream1.requestFocus();
mVideoViewStream1.start();
} catch (Exception e) {
dismissDialog();
Log.e(TAG, "Error" + e.getMessage());
e.printStackTrace();
}
dismissDialog();
}
@Override
public void onCompletion(MediaPlayer mp) {
this.mIndex++;
if (this.mIndex < mChannelPlaylist.getSchedule().size()) {
this.mURL = this.mChannelPlaylist.getSchedule().get(this.mIndex).getStream_url();
standardAndroidPlayer();
} else {
finish();
}
}
/**
* Creates a progress dialog
*/
private void progressDialog() {
// Create a progressbar
mDialog = new ProgressDialog(VideoActivity.this);
// Set progressbar title
mDialog.setTitle("Android Video Streaming Tutorial");
// Set progressbar message
mDialog.setMessage("Buffering...");
mDialog.setIndeterminate(false);
mDialog.setCancelable(false);
// Show progressbar
mDialog.show();
}
}
편집 : 여기
비디오 재생을 처리하는 활동이다 태블릿에 사용하면 좋아, 어떤 이상한 이유로, 휴대 전화의 방법은 그러나, 오프 발생하지 않습니다, 그렇습니다. 나는 태블릿에서 그 효과를 재현 할 수 없었고 전화에서도 성공하지 못했습니다. 그것은 안드로이드의 버전과 관련이 있습니까? 청취자를 쓸 때 호환성에 대한 경고를 얻지 못했기 때문에 그것에 대해별로 생각하지 않았습니다.
코드/응답을 설명해야합니다. – Raptor
활동에 OnCompletionListener가 이미 있습니다. 유일한 차이점은 내가 (이)를 사용하고 직접 호출하지 않고 메소드를 작성한 것입니다. 앞서 언급 한 솔루션을 시도했지만 OP에서 언급 한 것과 동일한 결과/문제가있었습니다. – arhon