Estou fazendo um NavigationDrawer
, e daí tenho que fazer algumas adaptações, pois estou estendendo Fragment
, mas preciso usar int's para Activity funcionar, tentei chamar dentro de OnCreateView
o FragmentActivity
mas não deu muito certo.
É esta classe aqui:
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();
}
}
Do modo que está é insustentável, pois está como Fragment, como faço adaptações com Activity de determinadas funções como setar o player para tocar com o findByViewId ou controlar o volume com o Seek Bar.