From 7db3b0f9f93528c55aa91d6f37f704949caad9ed Mon Sep 17 00:00:00 2001 From: lukeIam Date: Tue, 30 Dec 2014 15:52:15 +0100 Subject: [PATCH] [Server] More audio formats for streaming --- ServerLib/CWebservice.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/ServerLib/CWebservice.cs b/ServerLib/CWebservice.cs index 1dbb6430..3a085350 100644 --- a/ServerLib/CWebservice.cs +++ b/ServerLib/CWebservice.cs @@ -322,7 +322,6 @@ namespace ServerLib { if (WebOperationContext.Current != null) { - WebOperationContext.Current.OutgoingResponse.ContentType = "audio/mpeg"; WebOperationContext.Current.OutgoingResponse.LastModified = DateTime.UtcNow; WebOperationContext.Current.OutgoingResponse.Headers.Add( HttpResponseHeader.Expires, @@ -334,13 +333,37 @@ namespace ServerLib path = path.Replace("..", ""); - if (!File.Exists(path) || !(path.EndsWith(".mp3", StringComparison.InvariantCulture) || path.EndsWith(".ogg", StringComparison.InvariantCulture))) + if (!File.Exists(path) + || !(path.EndsWith(".mp3", StringComparison.InvariantCulture) + || path.EndsWith(".ogg", StringComparison.InvariantCulture) + || path.EndsWith(".wav", StringComparison.InvariantCulture) + || path.EndsWith(".webm", StringComparison.InvariantCulture))) { if (WebOperationContext.Current != null) WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound; return null; } + if (WebOperationContext.Current != null) + { + if (path.EndsWith(".mp3", StringComparison.InvariantCulture)) + { + WebOperationContext.Current.OutgoingResponse.ContentType = "audio/mpeg"; + } + else if (path.EndsWith(".ogg", StringComparison.InvariantCulture)) + { + WebOperationContext.Current.OutgoingResponse.ContentType = "audio/ogg"; + } + else if (path.EndsWith(".wav", StringComparison.InvariantCulture)) + { + WebOperationContext.Current.OutgoingResponse.ContentType = "audio/wav"; + } + else if (path.EndsWith(".webm", StringComparison.InvariantCulture)) + { + WebOperationContext.Current.OutgoingResponse.ContentType = "audio/webm"; + } + } + return File.OpenRead(path); } #endregion