也许我的问题标题可能是错的,我不能尝试太大的标题,但问题是我试图在ajax请求中添加播放列表中的歌曲。
在jplayer我创建了播放列表并使用setPlaylist函数设置歌曲,这很好用。问题是,当我点击专辑按钮时,它开始播放歌曲,我希望它暂停。
这是我的歌曲功能:
private TextView textresponse1;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button Get= (Button) findViewById(R.id.httprequest);
textresponse1= (TextView)findViewById(R.id.textresponse);
progressDialog=new ProgressDialog(this);
Get.setOnClickListener(this);
}
@Override
public void onClick(View v) {
new JSONTask().execute("https://jsonparsingdemo-cec5b.firebaseapp.com/jsonData/moviesDemoList.txt");
progressDialog.setMessage("Collecting Data");
progressDialog.show();
}
public class JSONTask extends AsyncTask<String,String,String >{
@Override
protected String doInBackground(String... params) {
BufferedReader reader = null;
HttpURLConnection connection = null;
try {
URL url=new URL(params[0]);
connection=(HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream=connection.getInputStream();
reader=new BufferedReader(new InputStreamReader(stream));
String line="";
StringBuffer buffer=new StringBuffer();
while ((line = reader.readLine())!=null) {
buffer.append(line);
}
String finaljosn=buffer.toString();
StringBuffer add =new StringBuffer();
JSONObject parentobject=new JSONObject(finaljosn);
JSONArray parentarray=parentobject.getJSONArray("movies");
for(int i=0;i<parentarray.length();i++) {
JSONObject moviename = parentarray.getJSONObject(i);
String finalmovie = moviename.getString("movie");
int finalyear = moviename.getInt("year");
add.append(finalmovie +"- "+finalyear + "\n");
}
return add.toString();
// return finalmovie +" -Rushabh- " +finalyear;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (connection!=null) {
connection.disconnect();
}
try {
if (reader!=null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
progressDialog.dismiss();
textresponse1.setText(result);
}
}
在按钮上我做了这个:AddSongToPlaylist(song_object)
我的歌是对象类,它将歌曲添加到songList,然后我使用.getSongList
选择歌曲但我不认为会有任何问题,但可能有解决方案,只有当没有匹配的歌曲添加到列表时,我才可以运行AddSongToPlaylist(songs) {
songs.filter((song) => {
self.MySong.addSong(song);
self.MySong.setUser(song.user_id);
myplayer.setPlaylist(self.MySong.getSongList());
});
}
功能一次。
如果有人试过,请告诉我。
答案 0 :(得分:0)
如果没有更多细节,这是不可能正确回答的。单击专辑按钮调用的功能是什么?您指定了哪些jPlaylist选项?
jPlaylist的setPlaylist
功能会自动播放媒体,如果您在播放列表选项中将autoplay
选项设置为true。
如果不是这种情况,请提供更多详细信息。