Click here to Skip to main content
15,902,715 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Dear Everybody,
I am trying to play radio for my module. And catched stream: http://210.245.60.242:1935/vov3/vov3/playlist.m3u8[^]
But my module only supports file: mp3, wav, mp2, WMP.
So can you help me give a solution for this trouble? How the way to i can play that stream :(.
Thank you so much.

What I have tried:

I tried file audio using vlc and media player, which can play.
Posted
Updated 11-Apr-16 6:22am
Comments
Richard MacCutchan 11-Apr-16 6:58am    
Have you checked the content of that file? It does not look like a stream to me.

1 solution

M3U[^] is a playlist; it's a plain-text file containing a list of URLs representing the files to play, and optionally comment lines starting with #.

You'll need to read the contents of the file, extract any URLs, and process them accordingly:
C#
IEnumerable<Uri> LoadPlaylist(Uri source)
{
    using (var client = new WebClient())
    {
        var processedPlaylists = new HashSet<Uri>();
        var playlists = new Queue<Uri>();
        playlists.Enqueue(source);
        
        while (playlists.Count != 0)
        {
            Uri playlistUri = playlists.Dequeue();
            if (!processedPlaylists.Add(playlistUri)) continue;
            
            string playlistContent = client.DownloadString(playlistUri);
            string[] playlistLines = playlistContent.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            
            foreach (string line in playlistLines)
            {
                if (string.IsNullOrWhiteSpace(line)) continue;
                if (line[0] == '#') continue;
                
                Uri file;
                if (!Uri.TryCreate(source, line, out file))
                {
                    Console.WriteLine("Invalid line: '{0}'", line);
                    continue;
                }
            
                string extension = Path.GetExtension(file.LocalPath);
                if (extension.StartsWith(".m3u", StringComparison.OrdinalIgnoreCase))
                {
                    playlists.Enqueue(file);
                }
                else
                {
                    yield return file;
                }
            }
        }
    }
}

Running that against the URL in your question produces three .aac files:
Advanced Audio Coding - Wikipedia, the free encyclopedia[^]

If you want to use that playlist, then you'll need to update your module to support that file type.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900