• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Fragment playing audio stream

jfm1504

Lurker
Mar 1, 2022
1
0
Is it possible to have something like that working ?

public class RadiosFragment extends Fragment implements View.OnClickListener {
ArrayList<String> stringURL = new ArrayList<>();
private AudioManager mAudioManager;
MediaPlayer mp = new MediaPlayer();
@override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myView = inflater.inflate(R.layout.fragment_radios, container, false);
Button btn1 = (Button) myView.findViewById(R.id.btn1);
btn1.setOnClickListener(this);
return myView;
}
@override
public void onClick (View myView) {
switch (myView.getId()) {
case R.id.btn1:
String url="http://radioweb.com/daily.mp3";
MediaPlayer mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
//mp.setDataSource(url);
mp.prepare();
mp.start();
}
}
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones