Jump to content
Linuxuser1234

How can i stream audio from mediaplayer with idhttp

Recommended Posts

in delphi i made a popup window that looks like a weather radio and i would like to stream audio from a website url using idHTTP and then streaming the audio from that website using Tmediaplayer component 

i cant find any working examples anyone have any suggestions on how i can connect to a website and stream audio from a mediaplayer on button click 

Share this post


Link to post

@Remy Lebeau i wrote this idhttp how would i use this procedure when i click on a button i have tried override but that wouldn't work 

procedure TForm7.IdHTTP1Authorization(Sender: TObject;
  Authentication: TIdAuthentication; var Handled: Boolean);
var
get_url: string;
resp: TmemoryStream;
begin
// connect to weatherusa
get_url := 'https://radio.weatherusa.net/NWR/KEC61_2.mp3';
resp := TMemoryStream.Create;
idHTTP1.Get(get_url+'v', resp);
end;

 

Share this post


Link to post
3 hours ago, Linuxuser1234 said:

@Remy Lebeau i wrote this idhttp how would i use this procedure when i click on a button i have tried override but that wouldn't work 

Why are you sending a new HTTP request from inside the TIdHTTP.OnAuthorization event?  There is already an HTTP request in progress when that event is fired, it is asking you to provide credentials for that request.

 

If you look at the example more carefully, it is not even using TIdHTTP to stream the actual media, TMediaPlayer is handling that internally.  TIdHTTP is simply being used to retrieve a list of available media URLs from a server, and then a selected URL is given directly to TMediaPlayer to play, one at a time.

 

So, what is stopping you from doing the same thing in your code?  Did you even try giving TMediaPlayer a media URL to play?

MediaPlayer1.FileName := 'https://radio.weatherusa.net/NWR/KEC61_2.mp3';
MediaPlayer1.Play;

If that still doesn't work, then see my earlier StackOveflow answer to How play .mp3 files loaded from a URL in TMediaPlayer with Firemonkey?

Edited by Remy Lebeau

Share this post


Link to post

@Remy Lebeau i dont hear any audio and  after i close the popup window i cant close out of my main application like i have to go to task manager and close it from there but the main app doesn't freeze or anything i can still open my popup windows 

procedure TForm7.Button1Click(Sender: TObject);
//This Button Connects to weatherusa radio server and change
//a few labels caption
begin
Label2.Text := '162.550 MHz';
Label6.Text := 'Status: Connected';
Label5.Text := 'KEC61';  //default Wx radio Station
Label7.Text := 'AL'; //default state
Label8.Text := 'Mobile';
Button1.Text := 'Click to disconnect from weatherusa.net';
MediaPlayer1.FileName := 'https://radio.weatherusa.net/NWR/KEC61_2.mp3';
MediaPlayer1.Play;

 

Share this post


Link to post

and yes i have check the stackoverflow answers from the link that you sent and i still get the same result MediaPlayer1.FileName := 'https://radio.weatherusa.net/NWR/KEC61_2.mp3'; 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×