Back to project page Streamplay.
The source code is released under:
Copyright 2014 A-z-f
If you think the Android project Streamplay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.streamplay.activities; //from www . j a v a 2 s . c o m import java.util.ArrayList; import java.util.HashMap; import org.json.JSONArray; import org.json.JSONException; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast; import com.example.streamplay.R; import com.example.streamplay.libs.MusicPlayer; public class PlayerActivity extends Activity { ArrayList<HashMap<String, String>> tracklist = new ArrayList<HashMap<String, String>>(); private static final String NODE = "track"; private String _album; private String _tracksList; private MusicPlayer _oPlayer; private Integer currentTrackPosition = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.player);// toujours au dbut TextView albumName = (TextView) findViewById(R.id.albumTitle); ListView list = (ListView) findViewById(R.id.tracks); Intent intent = getIntent(); _tracksList = intent.getStringExtra(MainActivity.TRACKS); _album = intent.getStringExtra(MainActivity.ALBLUM); albumName.setText(_album); String baseUrl = MainActivity.WEBSERVER+"Music/"+_album+"/"; _oPlayer = new MusicPlayer(tracklist,baseUrl,NODE); JSONArray jObject = null; try { jObject = new JSONArray(_tracksList); } catch (JSONException e) { e.printStackTrace(); } for (int i = 0; i < jObject.length(); i++) { try { HashMap<String, String> map = new HashMap<String, String>();// String track = new String(jObject.getString(i)); map.put("track", track); tracklist.add(map); SimpleAdapter simpleAdpt = new SimpleAdapter(this, tracklist, R.layout.item, new String[] { "track" }, new int[] { R.id.item }); list.setAdapter(simpleAdpt); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText( PlayerActivity.this, "Track " + tracklist.get(position).get("track"), Toast.LENGTH_SHORT).show(); currentTrackPosition = position; } }); } catch (JSONException e) { e.printStackTrace(); } } } public boolean onClick(View v) { switch (v.getId()) { case R.id.btn_play: _oPlayer.Play(currentTrackPosition); break; case R.id.btn_pause: _oPlayer.Pause(); break; /*case R.id.btn_stop: _oPlayer.Stop(); break;*/ case R.id.btn_next: _oPlayer.Next(); break; case R.id.btn_prev: _oPlayer.Prev(); break; } return true; } }