好吧,我想我的问题描述了自己,不管怎样,这里是代码
public class NowPlaying extends Activity implements Serializable {
static MediaPlayer mp =new MediaPlayer();
String artist;ProgressDialog pd;
int position; String key=null ;
/*int z=0;
SeekBar songProgressBar ;
TextView songCurrentDurationLabel;
TextView songTotalDurationLabel ;
private Handler mHandler = new Handler();
private Utilities utils=new Utilities();
*/
@SuppressLint("NewApi")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.now_playing);
Intent i = getIntent();
position=i.getIntExtra("Data2", 0);
/* songProgressBar = (SeekBar) findViewById(R.id.songProgressBar);
songCurrentDurationLabel = (TextView) findViewById(R.id.songCurrentDurationLabel);
songTotalDurationLabel = (TextView) findViewById(R.id.songTotalDurationLabel);
*/
final ArrayList<SongDetails> songs = getIntent().getParcelableArrayListExtra("Data1");
pd = new ProgressDialog(this);
pd.setMessage("Loading...");
Playservice(songs,position );
Button bfake=(Button) findViewById(R.id.bFake);
LinearLayout LL=(LinearLayout) findViewById(R.id.LL);
Button Pause=(Button)findViewById(R.id.bPlayPause);
// songProgressBar.setOnSeekBarChangeListener((OnSeekBarChangeListener) this); // Important
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer player) {
position=position+1;
Playservice(songs,position);
}});
bfake.setOnTouchListener(new OnSwipeTouchListener()
{ public void onSwipeRight() {
position=position-1;
Playservice(songs,position );
}
public void onSwipeLeft() {
position=position+1;
Playservice(songs,position );
}
public void onSwipeBottom() {
mp.stop();
}
});
LL.setOnTouchListener(new OnSwipeTouchListener() {
public void onSwipeBottom() {
mp.stop();
}
});
Pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{if(mp.isPlaying())
mp.pause();
else
mp.start();
}
});
}
private void Playservice( ArrayList<SongDetails> songs, int position )
{
int currentPosition= 0;
int total = mp.getDuration();
/* while (mp!=null && currentPosition<total) {
try {
Thread.sleep(1000);
currentPosition= mp.getCurrentPosition();
} catch (InterruptedException e) {
break;
} catch (Exception e) {
break;
}
// songProgressBar.setProgress(currentPosition);
*/
try {
String ab=songs.get(position).getPath2().toString();
artist=songs.get(position).getArtist();
new Xmlparse().execute();
if(mp.isPlaying())
{ mp.stop();
}
mp.reset();
mp.setDataSource(ab) ;
mp.prepare();
mp.start();
// songProgressBar.setProgress(0);
// songProgressBar.setMax(mp.getDuration());
new Thread().start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
/*public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if(fromUser) mp.seekTo(progress);
}
*/
class Xmlparse extends AsyncTask<Void,Drawable,Drawable>
{
protected void onPostExecute(Drawable result) {
// super.onPostExecute(result);
pd.dismiss();
LinearLayout LL=(LinearLayout) findViewById(R.id.LL);
LL.setBackgroundDrawable(result);
// Toast.makeText(getApplicationContext(),result, 1000).show();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pd.show();
}
@Override
protected Drawable doInBackground(Void... params) {
Drawable s =getData();
return s;
}
public Drawable getData()
{ Drawable drawable = null;//=new BitmapDrawable(bmp);
artist=artist.trim();
artist=artist.replace(" ", "%20");
try{
URL url = new URL("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=" +artist+ "&api_key=1732077d6772048ccc671c754061cb18");
URLConnection connection = url.openConnection();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
final Document document = db.parse(connection.getInputStream());
document.getDocumentElement().normalize();
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xPathEvaluator = xPathfactory.newXPath();
XPathExpression nameExpr = xPathEvaluator.compile("//lfm/artist/image");
// XPathExpression nameExpr = xPathEvaluator.compile("//lfm/tracks/track/image");
NodeList nl = (NodeList) nameExpr.evaluate(document, XPathConstants.NODESET);
for (int zzz = 0; zzz < nl.getLength(); zzz++)
{
Node currentItem = nl.item(zzz);
key = currentItem.getTextContent();
// key = currentItem.getAttributes().getNamedItem("uri").getNodeValue();
}URL ulrn = new URL(key);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
drawable=new BitmapDrawable(bmp);
}
catch(Exception e)
{}
return drawable;}
}}
它重新启动,因为您的活动已重新创建...每次用户更改设备的方向时,都会再次调用oncreate方法。要修复此问题,请将以下内容添加到清单文件中的活动中:
android:configChanges="orientation|keyboardHidden">
我用Inno Setup做了一个安装程序,在一些文件运行后我需要重启电脑,所以我用了这篇文章中的解决方案。 inno安装示例“CodePrepareToInstall”。iss运行良好,所以我使用了代码进行测试安装,但计算机重新启动后安装程序无法启动。 两个安装程序(inno demo和我的测试)都在“HKLM\Software\Microsoft\Windows\CurrentVersion\R
Triathlon程序执行一个长时间运行的任务,如果该任务已完全执行,则有可能重新启动该任务。我想添加停止执行以重置UI的可能性。为了达到这个目的,我增加了一个新的按钮,停止。代码如下: 如果任务已经完成,程序很好地重新启动,但是如果我在停止它之后调用start,程序就会崩溃。我该纠正什么?
这个问题与这里提出的问题基本相似:Apache Flink容错。i、 e.如果作业在两个检查点之间重新启动,会发生什么情况?它会重新处理在最后一个检查点之后已经处理过的记录吗? 例如,我有两份工作,工作1和工作2。Job1使用来自Kafka的记录,对其进行处理,然后再次将其生成到第二个Kafka主题。Job2使用第二个主题并处理记录(在我的例子中,它使用AerospikeClient更新aeros
问题内容: 我很难找到一种方法来启动,停止和重新启动Java中的线程。 具体来说,我在中有一个类Task(当前实现)。我的主应用程序需要能够在线程上启动此任务,在需要时停止(杀死)该线程,有时还可以杀死并重新启动该线程… 我的第一次尝试是与,但我似乎找不到办法重新启动任务。当我使用任何将来的呼叫失败时,因为是“关机” … 那么,我该怎么做呢? 问题答案: 一旦线程停止,你将无法重新启动它。但是,没
我使用的是Centos7.6,主线是nginx,安装了nginx.org的最新版本。 [root@host~]#systemctl status nginx.service*nginx.service-nginx-高性能web服务器已加载:已加载(/usr/lib/systemd/system/nginx.service;已启用;供应商预置:已禁用)活动:活动(运行)自Tue 2019-06-25
docker合成文件: