2
Good evening guys, does anyone know any tutorial or ever worked how to make a radio web application? It will only stream audio streaming that is already online.
2
Good evening guys, does anyone know any tutorial or ever worked how to make a radio web application? It will only stream audio streaming that is already online.
2
It had also been fought in the beginning, but after studies I found two solutions, both I like, I have tried both, but the second seems to be more stable by the implementation offered in the line of code. You have two options (in addition to others, but they usually only work when you’re just in the app):
The second example, already works in Kitkat, the first has to adapt.
Well, I’m going to show you an example with 1°, from this class, that does all the transfer to run in the background.
private StreamingMediaPlayer streamMedia;
//Para verificar se está tocando o não, quando aperta o botão:
private Boolean isPlaying;
//Para apertar o play (neste caso, a pausa utiliza do mesmo ID, que é este que é setado no momento de executá-lo).
private ImageButton playButton;
//Dentro do OnCreateView() além de indicar o layout fazemos o seguinte:
urlStreaming = "http://linktransmissao.com/live.mp3";
//Lembrando que é aonde o fluxo é transmitindo, não a aba preparada para o navegador.
//Indicando quem éo playButton do XML:
playButton = ((ImageButton)findViewById(R.id.button_play));
//Quando usuário clicar para tocar:
playButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
//Quando for parar através do interrupt(), aparecer a imagem de play, para tocar novamente
if (isPlaying)
{
audioStreamer.interrupt();
playButton.setImageResource(R.drawable.button_play);
}
//Quando for executar através do startStreamingAudio(), aparecer a imagem de pausa, caso deseje não ouvir mais.
if (!isPlaying)
{
startStreamingAudio();
playButton.setImageResource(R.drawable.button_pause);
}
isPlaying=!isPlaying;
}
});
}
private void startStreamingAudio()
{
try
{
//O áudio do streaming está funcionando, tentá-lo para-lo:
if (this.audioStreamer != null)
this.audioStreamer.interrupt();
//Chamando para um novo funcionamento pelo contexto, o mesmo playButton orientado na devida classe e a partir do url de valor String instanciado:
this.audioStreamer = new StreamingMediaPlayer(this, playButton);
this.audioStreamer.startStreaming(this.urlStreaming, 5208L, 216L);
return;
}
//Caso um eventual problema de execução, servindo para o sistema, não ao usuário:
catch (IOException localIOException)
{
while (true)
Log.e(getClass().getName(), "Error starting to stream audio.", localIOException);
}
}
//Por último para não ficar executando "infinitamente" o onDestroy() literalmente acaba com o áudio-o interrompendo para quando a aplicação está sendo encerrada, pois apenas fechá-la não faria parar de sair som.
protected void onDestroy()
{
super.onDestroy();
if (this.audioStreamer != null)
this.audioStreamer.interrupt();
}
In XML you can mount using Past variables that fit into the context. You can adapt as you like, with other features, which can be edited in StreamingMediaPlayer
also, as an example the ProgressDialog
personalized.
One option for volume control is SeekBar
:
private void definirVolumeSlider()
{
//Utilizando o sistema de áudio do Android, faz-se necessário importar o AudioManager, dois valores inteiro para o indicar o volume, indicando-o como máximo para 3 e o outro conforme pressionado, o progress referindo-se ao j, pois é o que é movimentado com o dedo para regular o volume como queira.
this.audioManager = ((AudioManager)getSystemService("audio"));
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);
//Clicando então para selecionar, inicialmente no máximo:
localSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar paramAnonymousSeekBar, int paramAnonymousInt, boolean paramAnonymousBoolean)
{
audioManager.setStreamVolume(3, paramAnonymousInt, 0);
}
//Este dois últimos seria mais para música propriamente dito, para as trilhas:
public void onStartTrackingTouch(SeekBar paramAnonymousSeekBar)
{
}
public void onStopTrackingTouch(SeekBar paramAnonymousSeekBar)
{
}
});
}
To put notification, I did the following:
private void notification()
{
NotificationManager localNotificationManager = (NotificationManager)getSystemService("notification");
PendingIntent localPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, Nomedaclasseemquestao.class), 0);
localNotificationManager.notify(1, new Notification.Builder(this).setSmallIcon(2130837515).setContentTitle("Seu título aqui. Ex: nome da rádio").setContentText("Texto. Ex:slogan da rádio").setOngoing(true).setContentIntent(localPendingIntent).build());
}
To the isPlaying
//Quando está sem tocar, sem aparecer notificação
((NotificationManager)RadioStation.this.getSystemService("notification")).cancel(1);
To the !isPlaying
//Está tocando, a notificação fica visível
notification();
The problem of touching Kitkat is the protocol: just do it like this to solve the Broadcast Encounter on Oncreateview():
String str = "http";
//Corrigindo o bug do ICY (Icecast, tipo de transmissão depois do API 18)
if (Build.VERSION.SDK_INT >= 19)
{
setupIcyURLStreamHandler();
str2 = "icy";
}
urlStreaming = (str2 + "://linktransmissao.com/live.mp3");
//Construindo então o método citado:
private void setupIcyURLStreamHandler()
{
try
{
URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
public URLStreamHandler createURLStreamHandler(String paramAnonymousString) {
Log.d("LOG", "Asking for stream handler for protocol: '" + paramAnonymousString + "'");
if ("icy".equals(paramAnonymousString)) ;
for (IcyURLStreamHandler localIcyURLStreamHandler = new IcyURLStreamHandler(); ; localIcyURLStreamHandler = null)
return localIcyURLStreamHandler;
}
});
return;
}
catch (Throwable localThrowable)
{
while (true)
Log.w("LOG", "Cannot set the ICY URLStreamHandler - maybe already set ? - " + localThrowable);
}
}
In this case, enjoy the class IcyURLStreamHandler
of the same AAC Decoder, placing the package com.spoledge.aacdecoder
in libs
.
To use the AAC Decoder
can be based on this example of who provided:https://code.google.com/p/aacdecoder-android/source/browse/trunk/player/src/com/spoledge/aacplay/AACPlayerActivity.java*.
* Spolecne, 2011. spoledge.com
Browser other questions tagged android streaming
You are not signed in. Login or sign up in order to post.
Just a kickoff http://www.sitepoint.com/develop-music-streaming-android-app/ Then transfer as reply @Kaynancoelho
– Wellington Avelino
Thank you Wellington. Very useful.
– Kaynan Coelho
I’ll see if I can post an example today to you @Kaynancoelho
– Wellington Avelino
I am grateful @Wellingtonavelino for your help, anxiously awaiting your example.
– Kaynan Coelho