Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I recently created a wcf service c# music app for listening and downloading music tracks for consuming data for a front-end Android music streaming app. Everything works good accept the performance of waiting for the music request to finish buffering the entire track from the server to respond back to the client (Android app). First of all, and for most I am very new to the Stream classes and the concept of which one will give me the best performance for streaming mp3 files on a web server (IIS).

Below here is my code that I'm currently is using for my music mp3 file. Can anyone please help or assist me with picking the approciate Stream class (FileStream or BinaryStream or etc.) and show me an example. Your help will gladely be appreciated.

What I have tried:

My data contract is simply this:
[DataMember] public string TrackUrl { get; set; } 

My service contract:

[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "GET", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, UriTemplate = "LoadTracksByAlbum/{AlbumID}")]
List<LoadAlbumTracks> LoadTracksByAlbum(string AlbumID); 

My  proxy operation contract method implementation:

public List<LoadAlbumTracks> LoadTracksByAlbum(string AlbumID)
        {
            List<LoadAlbumTracks> loadAlbumTracksList1 = new List<LoadAlbumTracks>();
            MusicDataContext tapesDataContext = new MusicDataContext();
            CultureInfo cultureInfo = CultureInfo.GetCultureInfo("en-US");
            tapesDataContext.CommandTimeout = 0;
            foreach (proc_TracksLoadByAlbumResult loadByAlbumResult in (IEnumerable<proc_TracksLoadByAlbumResult>)tapesDataContext.proc_TracksLoadByAlbum(new int?(Convert.ToInt32(AlbumID))))
            {
                List<LoadAlbumTracks> loadAlbumTracksList2 = loadAlbumTracksList1;
                LoadAlbumTracks loadAlbumTracks1 = new LoadAlbumTracks();
                loadAlbumTracks1.TrackID = loadByAlbumResult.TrackID;
                loadAlbumTracks1.TrackTitle = loadByAlbumResult.TrackTitle;
                loadAlbumTracks1.Artists = loadByAlbumResult.Atists;
                loadAlbumTracks1.DiscJockeyName = loadByAlbumResult.DiscJockeyName;
                loadAlbumTracks1.TrackDescription = loadByAlbumResult.TrackDescription;
                loadAlbumTracks1.TrackUrl = loadByAlbumResult.TrackUrl;
                loadAlbumTracks1.AlbumID = loadByAlbumResult.AlbumID ?? 0;
                loadAlbumTracks1.AlbumCoverPhotoUrl = loadByAlbumResult.AlbumCoverPhotoUrl;
                loadAlbumTracks1.AlbumName = loadByAlbumResult.AlbumName;
                loadAlbumTracks1.TotalStreams = loadByAlbumResult.TotalStreams;
                LoadAlbumTracks loadAlbumTracks2 = loadAlbumTracks1;
                loadAlbumTracks1.DownloadStatus = loadByAlbumResult.DownloadStatus; 
                bool? trackStatus = loadByAlbumResult.TrackStatus;
                int num = trackStatus.HasValue ? (trackStatus.GetValueOrDefault() ? 1 : 0) : 1;
                loadAlbumTracks2.TrackStatus = num != 0;
                loadAlbumTracks1.DjID = loadByAlbumResult.DjID ?? 0;
                loadAlbumTracks1.CreatedBy = loadByAlbumResult.CreatedBy ?? 0;
                loadAlbumTracks1.CreatedOn = !loadByAlbumResult.CreatedOn.HasValue ? "" : loadByAlbumResult.CreatedOn.Value.ToString("d", (IFormatProvider)cultureInfo);
                loadAlbumTracks1.UpdatedBy = loadByAlbumResult.UpdatedBy ?? 0;
                loadAlbumTracks1.UpdatedOn = !loadByAlbumResult.UpdatedOn.HasValue ? "" : loadByAlbumResult.UpdatedOn.Value.ToString("d", (IFormatProvider)cultureInfo);
                LoadAlbumTracks loadAlbumTracks3 = loadAlbumTracks1;
                loadAlbumTracksList2.Add(loadAlbumTracks3);
            }
            return loadAlbumTracksList1;
        }
Posted
Updated 22-Dec-19 7:59am
Comments
[no name] 22-Dec-19 9:05am    
Get your own fibre-optics backbone.

Quote:
which one will give me the best performance for streaming mp3 files on a web server (IIS).
That is impossible to answer as it depends on many different factors, all of which will vary from country to country, ISP to ISP, and server to server. The only way to decide which is best for you is to run performance tests.
 
Share this answer
 
Comments
Dalerico 22-Dec-19 21:19pm    
Thanks for the response, but I didn’t really make my question clear as I should have. Please let me reiterate my question. Can you show me a example of how I could covert the above code to stream for that particular IService Contract.

Example: buffered mode - List<loadalbumtracks> LoadTracksByAlbum(string AlbumID); vs stream mode List<stream> LoadTracksByAlbum(string AlbumID);

Do you have any ideals how I could possibly implement the above proxy Service (LoadTracksByAlbum method) to wrap the TrackUrl property to stream the mp3 file. The TrackUrl property, which is in the foreach statement is where the mp3 file path exist in SQL Server database. And this property basically gets the path of the music mp3 individually and pulls the actual file from a folder that's located on the web server of the application.
Richard MacCutchan 23-Dec-19 3:44am    
Sorry, but I do not have any examples. If there are any around then Google should be able to find them.
IIS is best used as a web server utilizing the HTTP protocol, which operates in a download then render fashion; and not as a streaming media server which would use RTSP (real time streaming protocol)- self explanatory on purpose.

Windows versions prior to Win 7 supported Windows Media Encoder which could transcode files into media streams, for a limited amount (<5) of clients. This has been replaced with MS Expression Encoder; which I have not used.
There was also a Windows Media Server package that could handle much larger client loads.

I do not know what works best these days as that is no longer in my line of work; perhaps you could utilize/extend the DLNA Server abilities that are native to Windows now.

Simple searches for "C# DLNA" comes up with both suggestions for servers and clients so this may be a viable method for you
 
Share this answer
 
Comments
Dalerico 22-Dec-19 21:21pm    
Thanks for the response, but I didn’t really make my question clear as I should have. Please let me reiterate my question. Can you show me a example of how I could covert the above code to stream for that particular IService Contract.

Example: buffered mode - List<loadalbumtracks> LoadTracksByAlbum(string AlbumID); vs stream mode List<stream> LoadTracksByAlbum(string AlbumID);

Do you have any ideals how I could possibly implement the above proxy Service (LoadTracksByAlbum method) to wrap the TrackUrl property to stream the mp3 file. The TrackUrl property, which is in the foreach statement is where the mp3 file path exist in SQL Server database. And this property basically gets the path of the music mp3 individually and pulls the actual file from a folder that's located on the web server of the application.
MadMyche 23-Dec-19 7:24am    
Sorry, I can not. I haven't worked with Streaming Media for many years; what I have is no longer viable due to the evolution of the landscape.
Dalerico 23-Dec-19 16:07pm    
Okay then, thanks anyway for your response.

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