question

OmerSorrenti-8730 avatar image
0 Votes"
OmerSorrenti-8730 asked LeonLu-MSFT answered

Socket Listener - Continuos Api call

I am writing an app that connects to a media server. This media server communicates its events to me via socket for which I will then have to operate on my interfaces. I was wondering what was the best way to stay connected to this socket port and listen for events and how to notify if it disconnects, and how to reconnect right after. Also I have a second problem, the media server communicates the progress of a song (seconds) to me via an API Rest call. IN the moment a song is playing I should make a call per second to get back the seconds of progress. While it doesn't seem like a very elegant way to me, what do you think is the best way to fix this in xamarin? Thanks so much

dotnet-xamarinforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered

Hello,​

Welcome to our Microsoft Q&A platform!

Do you use TcpClient to make connection? If so, if the TCP is disconnects, you want to re-connect it, A TcpClient instance can only be used to connect once. You can simply instantiate a new TcpClient, rather than trying to re-open a closed one.

client.Close();
client = new TcpClient();
client.Connect(host, port);


Also I have a second problem, the media server communicates the progress of a song (seconds) to me via an API Rest call. IN the moment a song is playing I should >make a call per second to get back the seconds of progress

You can get the length of Audio(seconds of audio), then decrease this seconds when you play it.

If you want to play the online audio, you can try to use MediaManager to achieve it, it provides the control to show the audio's progress.

Designed to be simple and easy to use
Native playback of media files from remote http(s), embedded and local sources
Native media notifications and remote controls
Queue and playback management by default
Playback status (Playing, Buffering, Loading, Paused, Progress)
Events for media handling to hook into


https://github.com/Baseflow/XamarinMediaManager

Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.