Go Back   Android Forums > Android Development > Application Development > App Inventor
Gamers - Check out our new sister sites!
Nintendo Wii U!    |    OUYA - $99 Android System!

test: Reply
 
LinkBack Thread Tools
Old October 23rd, 2012, 12:07 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Oct 2012
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Cry Problems with ProgressBar and Button Stop

Hello.
I am developing an application for online radio listening.
But I have two problems that I can not solve:
The first error is very problematic because when I give the play "play" button is activated stop "stop." So far so good, but if I press the Stop button before you start playing the audio, you stop off and activates the play but the application continues to play. This should not happen. I want the button to be pressed to activate when you begin to hear the audio, not when it starts to load.
The second is related to the ProgressBar. I do not know why it does not load the progress bar. If it shows but not charging.

Natlum is offline  
Reply With Quote
Sponsors
Old October 23rd, 2012, 12:08 PM   #2 (permalink)
New Member
Thread Author (OP)
 
Join Date: Oct 2012
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Default

I hope I have been explicit about the problems I have.
My Activity has this content:

import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListene r;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;

public class RadioActivity extends Activity implements OnClickListener {

private final static String RADIO_STATION_URL = "http://xxxxxxxxxxxxxxxxxxxx";

private ProgressBar playSeekBar;

private Button buttonPlay;

private Button buttonStopPlay;

private MediaPlayer player;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.radio);

initializeUIElements();

initializeMediaPlayer();
}

private void initializeUIElements() {

playSeekBar = (ProgressBar) findViewById(R.id.progressBar1);
playSeekBar.setMax(100);
playSeekBar.setVisibility(View.INVISIBLE);


buttonPlay = (Button) findViewById(R.id.buttonPlay);
buttonPlay.setOnClickListener(this);

buttonStopPlay = (Button) findViewById(R.id.buttonStop);
buttonStopPlay.setEnabled(false);
buttonStopPlay.setOnClickListener(this);

}

@Override
public void onClick(View v) {
if (v == buttonPlay) {
startPlaying();
} else if (v == buttonStopPlay) {
stopPlaying();
}
}


private void startPlaying() {
buttonStopPlay.setEnabled(true);
buttonPlay.setEnabled(false);

playSeekBar.setVisibility(View.VISIBLE);

player.prepareAsync();

player.setOnPreparedListener(new OnPreparedListener() {

@Override
public void onPrepared(MediaPlayer mp) {
player.start();
}
});
}

private void stopPlaying() {
if (player.isPlaying()) {
player.stop();
/**player.release();**/
player.reset();
player.release();
initializeMediaPlayer();
}

buttonPlay.setEnabled(true);
buttonStopPlay.setEnabled(false);
playSeekBar.setVisibility(View.INVISIBLE);
}

private void initializeMediaPlayer() {
player = new MediaPlayer();
try {
player.setDataSource(RADIO_STATION_URL);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {

@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
playSeekBar.setSecondaryProgress(percent);
Log.i("Buffering", "" + percent);
}
});
}


@Override
protected void onPause() {
super.onPause();
if (player.isPlaying()) {
/**player.stop();**/
/**stopPlaying();**/
}

}


@Override
protected void onStop(){
super.onStop();
if (player.isPlaying()){
stopPlaying();
}
}




}



And my layout is this one:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0069AD" >


<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="320dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/imgreproductor"
android:src="@drawable/reproductor" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="@string/URL" />

<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="@dimen/anchoBarra"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="2dp" />

<Button
android:id="@+id/buttonStop"
android:layout_width="@dimen/anchoPlay"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/progressBar1"
android:layout_below="@+id/progressBar1"
android:layout_marginTop="13dp"
android:text="@string/Stop" />

<Button
android:id="@+id/buttonPlay"
android:layout_width="@dimen/anchoPlay"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/buttonStop"
android:layout_alignBottom="@+id/buttonStop"
android:layout_alignLeft="@+id/progressBar1"
android:text="@string/Play" />

</RelativeLayout>


I hope your help and thank you very much beforehand.
greetings
Natlum is offline  
Reply With Quote
Reply
Tags
button, problems, progressbar, stop


Go Back   Android Forums > Android Development > Application Development > App Inventor
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:32 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.