我有一个代码,当我第一次启动应用程序时会通过mx播放器显示视频,它可以解决任何错误,但是如果我关闭并再次打开应用程序,它会显示活动mx播放器没有响应。当我按下后退按钮时如何关闭mx播放器。
我的代码:
公共类MainActivity扩展了Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
startMxPlayer(1, 1);
finish();
}
private void startMxPlayer(int tuner, int ch) {
int port = 8000 + tuner * 10 + ch;
Uri uri = Uri.parse("udp://224.1." + (port & 0xff) + ".1:" + port);
Log.v("server", "udp://224.1." + (port & 0xff) + ".1:" + port);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage( "com.mxtech.videoplayer.ad" );
intent.putExtra("end_by","user");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
getApplication().startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
最佳答案
没有人可能会停止杀死该进程,但我建议您以其他方式这样做。
private void startMxPlayer(int tuner, int ch) {
int port = 8000 + tuner * 10 + ch;
Uri uri = Uri.parse("udp://224.1." + (port & 0xff) + ".1:" + port);
Log.v("server", "udp://224.1." + (port & 0xff) + ".1:" + port);
// add the following line.
ActivityManager.killBackgroundProcesses("com.mxtech.videoplayer.ad");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage( "com.mxtech.videoplayer.ad" );
intent.putExtra("end_by","user");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
getApplication().startActivity(intent);
关于android - 如何在按下后停止android Mx Player,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22408413/