I'm doing NavigationDrawer
, and so I have to make some adaptations, as I'm extending Fragment
, but I need to use int's for Activity to work, I've tried calling OnCreateView
FragmentActivity
but it did not work very well.
It's this class here:
package player.kmk.com.kmk;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.SeekBar;
import java.io.IOException;
/**
* Created by Z0NEN on 10/22/2014.
*/
public class menu1_Fragment extends Fragment {
View rootview;
protected static final String TAG = null;
private AudioManager audioManager;
private StreamingMediaPlayer audioStreamer;
private boolean isPlaying;
private ImageButton playButton;
private String urlStreaming;
private menu1_Fragment station;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.menu1_layout, container, false);
// listen.ouvir();
// listen.definirVolumeSlider();
Bundle bundle;
playButton = ((ImageButton).findViewById(R.id.play_button));
this.playButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
if (isPlaying)
{
audioStreamer.interrupt();
playButton.setImageResource(R.drawable.play);
}
if (!isPlaying)
{
startStreamingAudio();
playButton.setImageResource(R.drawable.pause);
}
isPlaying=!isPlaying;
}
});
this.audioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE));
int i = this.audioManager.getStreamMaxVolume(3);
int j = this.audioManager.getStreamVolume(3);
setVolumeControlStream(3);
SeekBar localSeekBar = (SeekBar)findViewById(R.id.seekBar);
localSeekBar.setMax(i);
localSeekBar.setProgress(j);
localSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar paramAnonymousSeekBar, int paramAnonymousInt, boolean paramAnonymousBoolean)
{
audioManager.setStreamVolume(3, paramAnonymousInt, 0);
}
public void onStartTrackingTouch(SeekBar paramAnonymousSeekBar)
{
}
public void onStopTrackingTouch(SeekBar paramAnonymousSeekBar)
{
}
});
return rootview;
}
public void startStreamingAudio()
{
try
{
if (this.audioStreamer != null)
this.audioStreamer.interrupt();
this.audioStreamer = new StreamingMediaPlayer(this, playButton);
this.audioStreamer.startStreaming("http://sh.upx.com.br:10369", 5208L, 216L);
return;
}
catch (IOException localIOException)
{
while (true)
Log.e(getClass().getName(), "Error starting to stream audio.", localIOException);
}
}
public void onDestroy()
{
super.onDestroy();
if (this.audioStreamer != null)
this.audioStreamer.interrupt();
}
}
The way it is is unsustainable, because it's like Fragment, how do I make adaptations with Activity of certain functions like setar the player to play with findByViewId or control the volume with the Seek Bar.