1
I’m making a NavigationDrawer
, and then I have to make some adaptations, because I’m extending Fragment
, but I need to use int’s for Activity to work, I tried calling inside OnCreateView
the FragmentActivity
but it didn’t work out so well.
It’s this class right 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, as it is like Fragment, as I do adaptations with Activity of certain functions like set the player to play with findByViewId or control the volume with Seek Bar.
I will try and in the case of getSistemService()?
– Kauan Kubaski
Do getActivity(). getSystemService();
– Piovezan
You can show an example with getView()?
– Kauan Kubaski
Managed: playButton = (Imagebutton) getView(). findViewById(R.id.play_button); in the first case.
– Kauan Kubaski
Could not in this situation: this.audioManager = ((Audiomanager)getSystemService(Context.AUDIO_SERVICE)); .
– Kauan Kubaski
Well, the answer was accepted so I’m guessing it did. Anyway, it would be this.audioManager = (Audiomanager)(getActivity(). getSystemService(Context.AUDIO_SERVICE));
– Piovezan
Thank you. No . setVolumeControlStream(3) I put a getActivity() to pick up the activity and did not mark error, that’s right?
– Kauan Kubaski
That’s right yes.
– Piovezan
And in these cases it appears the error "Cannot resolve method get Intent`" what I do still using Activity in Fragment: feed = (Rssfeed) getIntent(). getExtras(). get("feed"); int pos = getIntent(). getExtras(). getInt("pos");
– Kauan Kubaski
Also, getActivity(). getIntent(). get...
– Piovezan
I had tried before asking and tried again but error appears where it invokes
– Kauan Kubaski
There I can no longer say what may be happening. From the error you quoted it seems that getIntent() is spelled wrong: "get Intent". Create a new question and provide more details.
– Piovezan
There is no spelling error, now it is to run. See here:http://answall.com/questions/109202/erro-call.
– Kauan Kubaski