Wednesday, October 30, 2013

i want play and pause button show at the bottom of all other activity page after that play song [android help]


i want play and pause button show at the bottom of all other activity page after that play song




public class Play_Radio extends Activity {

private ImageView playButton;
private TextView textStreamed, tv_radio_name, tv_radio_cat;
private boolean isPlaying;
private static StreamingMediaPlayer audioStreamer;
private AudioManager audioManager = null;
ImageView iv_like;
Dialog rankDialog;
RatingBar ratingBar, pre_rating;
float cus_rating;
AdView adView;
Dialog dialog;
public static String name, rating, like, radio_url, id, listner, image;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
setContentView(R.layout.play_radio);

/*
* LayoutInflater li = getLayoutInflater(); View layout =
* li.inflate(R.layout.customtoast, (ViewGroup)
* findViewById(R.id.custom_toast_layout)); Toast toast = new
* Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_LONG);
* toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
* toast.setView(layout); toast.show();
*/

// AdRequest adRequest = new AdRequest();
// adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
// adView = (AdView)findViewById(R.id.adView);
//

// For listner count
/*
*
* HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost =
* new HttpPost(
* "http://vaibhavtech.com/work/android/radio_listner.php"); try { //
* Add your data List nameValuePairs = new
* ArrayList(1); nameValuePairs.add(new
* BasicNameValuePair("id", Tab_Listner.id)); httppost.setEntity(new
* UrlEncodedFormEntity(nameValuePairs)); ResponseHandler
* responseHandler = new BasicResponseHandler(); String response =
* httpclient.execute(httppost, responseHandler);
*
* // This is the response from a php application String reverseString =
* response; Log.i("response", reverseString);
*
* } catch (ClientProtocolException e) { Log.i("CPE response ",
* e.toString()); // TODO Auto-generated catch block } catch
* (IOException e) { Log.i("IOException response ", e.toString()); //
* TODO Auto-generated catch block }
*/
if (audioStreamer != null) {
try {
Log.i("Already ply", "Succss");
audioStreamer.stop();

} catch (Exception e) {
}
} else {
Log.i("First time", "Play");

}
initControls();

}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.i("On Pause is call", "Succcess");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Log.i("Device Versoin is", "" + currentapiVersion);
if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
getMenuInflater().inflate(R.menu.main, menu);
Log.i("Android Device above", "Home Enbled");
}

return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub

switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
case R.id.home:
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Log.i("Home", "Press");
return true;

}
return super.onOptionsItemSelected(item);
}

// protected void onDestroy()
// {
// super.onDestroy();
//
//
// if ( audioStreamer != null)
// { audioStreamer.interrupt();
// }
//
// }

private void initControls() {
iv_like = (ImageView) findViewById(R.id.iv_activity_like);
iv_like.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Vibrator v1 = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v1.vibrate(40);
Toast.makeText(getApplicationContext(),
"Thanks For like Our Station", Toast.LENGTH_LONG)
.show();

// Like increament
/*
* HttpClient httpclient = new DefaultHttpClient(); HttpPost
* httppost = new HttpPost(
* "http://www.vaibhavtech.com/work/android/radio_like.php");
*
* try { // Add your data List nameValuePairs =
* new ArrayList( 1); nameValuePairs.add(new
* BasicNameValuePair("id", Tab_Listner.id));
*
*
*
* httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
*
* // Execute HTTP Post Request
*
* ResponseHandler responseHandler = new
* BasicResponseHandler(); String response =
* httpclient.execute(httppost, responseHandler);
*
* // This is the response from a php application String
* reverseString = response; Log.i("response", reverseString);
*
* } catch (ClientProtocolException e) { Log.i("CPE response ",
* e.toString()); // TODO Auto-generated catch block } catch
* (IOException e) { Log.i("IOException response ",
* e.toString()); // TODO Auto-generated catch block }
*/
}
});
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
textStreamed = (TextView) findViewById(R.id.text_kb_streamed);

playButton = (ImageView) findViewById(R.id.imageView1);
playButton.setEnabled(false);
playButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Log.i("Click sadg ", "success");

Vibrator v1 = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v1.vibrate(40);
if (audioStreamer.getMediaPlayer().isPlaying()) {
Log.i("play ", "success");
audioStreamer.getMediaPlayer().pause();
playButton.setImageResource(R.drawable.play_radio_play);
} else {
Log.i("pause", "success");
audioStreamer.getMediaPlayer().start();
audioStreamer.startPlayProgressUpdater();
playButton.setImageResource(R.drawable.play_radio_pause);
}
isPlaying = !isPlaying;
}
});

// rating radio sation

ImageView rankBtn = (ImageView) findViewById(R.id.iv_activity_rating);
rankBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
rankDialog = new Dialog(Play_Radio.this,
R.style.FullHeightDialog);
rankDialog.setContentView(R.layout.rating_bar);
rankDialog.setCancelable(true);
ratingBar = (RatingBar) rankDialog
.findViewById(R.id.dialog_ratingbar);
float userRankValue = 0;
// ratingBar.setRating(userRankValue);
ratingBar
.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar,
float rating, boolean fromUser) {
// TODO Auto-generated method stub
cus_rating = rating;

}
});

Button updateButton = (Button) rankDialog
.findViewById(R.id.rank_dialog_button);
updateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(Play_Radio.this,
"Thanks For Rating Our Stations",
Toast.LENGTH_LONG).show();
rankDialog.dismiss();
}
});
// now that the dialog is set up, it's time to show it
rankDialog.show();
}
});

String urlstring2 = Tab_Listner.radio_url;
Toast.makeText(Play_Radio.this, "Please Wait...", Toast.LENGTH_LONG)
.show();

startStreamingAudio(urlstring2);
tv_radio_cat = (TextView) findViewById(R.id.tv_play_radio_cat);
tv_radio_name = (TextView) findViewById(R.id.tv_play_radio_name);
tv_radio_name.setText(Tab_Listner.name);
pre_rating = (RatingBar) findViewById(R.id.ratingBar1);
pre_rating.setRating(Float.parseFloat(Tab_Listner.rating));
}

private void startStreamingAudio(String urlstring) {
try {
dialog = new Dialog(Play_Radio.this,
android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.progress_layout);
dialog.setTitle("loading...");
dialog.show();
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
if (audioStreamer != null) {
audioStreamer.interrupt();
}
audioStreamer = new StreamingMediaPlayer(this, textStreamed,
playButton, progressBar, dialog);
audioStreamer.startStreaming(urlstring, 5208, 216);

// streamButton.setEnabled(false);
// playButton.setEnabled(true);
} catch (Exception e) {
Log.e(getClass().getName(), "Error starting to stream audio.", e);
}

}

public void onItemSelected(AdapterView parent, View v, int position, long id) {
mSwitcher.setImageResource(mImageIds[position]);
}

public void onNothingSelected(AdapterView parent) {
}

public View makeView() {
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return i;
}

private ImageSwitcher mSwitcher;

public class ImageAdapter extends BaseAdapter {
public ImageAdapter(Context c) {
mContext = c;
}

public int getCount() {
return mThumbIds.length;
}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);

i.setImageResource(mThumbIds[position]);
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i.setBackgroundResource(R.drawable.picture_frame);
return i;
}

private Context mContext;

}

private Integer[] mThumbIds = { R.drawable.calculator, R.drawable.calendar,
R.drawable.camera };

private Integer[] mImageIds = { R.drawable.calculator, R.drawable.calendar,
R.drawable.camera };

}


i am create xml and how to show selected song in the bottom of all other activity in my app plz help me and you want to more info about this so i give you i want like tune in app after the song play its show on all other activity in this app i want to similarly to them.



Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...