Socket Listener - Continuos Api call

Omer Sorrenti 21 Reputation points
2021-03-26T16:35:01.42+00:00

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

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,416 Reputation points Microsoft Vendor
    2021-03-29T07:51:27.713+00:00

    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.

    0 comments No comments