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; // w w w . j av a2 s. c o m import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.content.ClipData.Item; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.Button; import android.widget.ListAdapter; 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.*; public class MainActivity extends Activity implements View.OnClickListener { // Navigate data public final static String TRACKS = "tracks"; public final static String ALBLUM = "album"; public final static String WEBSERVER = "http://192.168.0.13/WebServerStreaming/"; public JSONObject files = null; ListView list; TextView album; Button Btngetdata; ArrayList<HashMap<String, String>> albumlist = new ArrayList<HashMap<String, String>>(); // URL to get JSON Array JSONObject android = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public void onClick(View v) { new JSONParse().execute(); } public void getTracks(String Album, JSONArray tracks) { Intent i = new Intent(this, PlayerActivity.class); i.putExtra(TRACKS, tracks.toString()); i.putExtra(ALBLUM, Album.toString()); startActivity(i); } private class JSONParse extends AsyncTask<String, String, JSONObject> { private ProgressDialog pDialog; @Override protected void onPreExecute() { Log.d("onPreExecute", "onPreExecute start"); super.onPreExecute(); album = (TextView) findViewById(R.id.item); pDialog = new ProgressDialog(MainActivity.this); pDialog.setMessage("Getting Data ..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } protected JSONObject doInBackground(String... args) { JSONParser jParser = new JSONParser(); // Getting JSON from URL JSONObject json = jParser.getJSONFromUrl(WEBSERVER); return json; } protected void onPostExecute(JSONObject json) { pDialog.dismiss(); // Getting JSON Array from URL try { files = json.getJSONObject("files");// on recupre l'obj json Iterator iter = files.keys();// on crer un iterator avec les // cles de l'objet while (iter.hasNext()) {// tant qu'il y a des cles String key = (String) iter.next();// on rcupre la cles HashMap<String, String> map = new HashMap<String, String>();// map.put("album", key); albumlist.add(map); list = (ListView) findViewById(R.id.listView1); ListAdapter adapter = new SimpleAdapter(MainActivity.this, albumlist, R.layout.item, new String[] { "album" }, new int[] { R.id.item }); list.setAdapter(adapter); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText( MainActivity.this, "Go to " + albumlist.get(position).get( "album"), Toast.LENGTH_SHORT).show(); String album = albumlist.get(position).get("album"); try { getTracks(album, files.getJSONArray(album)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } } catch (JSONException e) { Log.d("onPostExecute", "Json parse fail :" + e.getMessage()); } finally { } } } }