Added mp3 streaming for songs and a player to the app (experimental)

This commit is contained in:
lukeIam committed 2014-12-09 17:58:42 +01:00
1 parent 18bdb7aa05
commit 1e71360366
7 files changed
+52 -2

No files matched your search

+2
View File
@@ -59,6 +59,8 @@ namespace ServerLib
public static GetAllSongsDelegate GetAllSongs { internal get; set; }
public static GetCurrentSongIdDelegate GetCurrentSongId { internal get; set; }
public static GetMp3PathDelegate GetMp3Path { internal get; set; }
#endregion
#region playlist
+29 -2
View File
@@ -37,7 +37,8 @@ namespace ServerLib
{
sessionKey = Guid.Parse(sessionHeader);
}
catch (Exception) {}
catch (Exception)
{ }
return sessionKey;
}
@@ -144,7 +145,7 @@ namespace ServerLib
public SProfileData[] GetProfileList()
{
if (CServer.GetProfileList == null)
return new SProfileData[] {};
return new SProfileData[] { };
return CServer.GetProfileList();
}
#endregion
@@ -308,6 +309,32 @@ namespace ServerLib
{
return CServer.GetAllSongs();
}
public Stream GetMp3File(int songId)
{
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "audio/mpeg";
WebOperationContext.Current.OutgoingResponse.LastModified = DateTime.UtcNow;
WebOperationContext.Current.OutgoingResponse.Headers.Add(
HttpResponseHeader.Expires,
DateTime.UtcNow.AddYears(1).ToString("r"));
}
String path = CServer.GetMp3Path(songId);
path = path.Replace("..", "");
if (!File.Exists(path) || !(path.EndsWith(".mp3", StringComparison.InvariantCulture) || path.EndsWith(".ogg", StringComparison.InvariantCulture)))
{
if (WebOperationContext.Current != null)
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
return null;
}
return File.OpenRead(path);
}
#endregion
#region playlist
+2
View File
@@ -111,6 +111,8 @@ namespace ServerLib
public delegate int GetCurrentSongIdDelegate();
public delegate string GetMp3PathDelegate(int songId);
[DataContract]
public struct SSongInfo
{
+5
View File
@@ -127,6 +127,11 @@ namespace ServerLib
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getAllSongs")]
SSongInfo[] GetAllSongs();
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getMp3?songId={songId}")]
Stream GetMp3File(int songId);
#endregion
#region playlist
+6
View File
@@ -73,6 +73,7 @@ namespace Vocaluxe.Base.Server
CServer.GetSong = _GetSong;
CServer.GetAllSongs = _GetAllSongs;
CServer.GetCurrentSongId = _GetCurrentSongId;
CServer.GetMp3Path = _GetMp3Path;
CServer.ValidatePassword = _ValidatePassword;
CServer.GetUserRole = _GetUserRole;
CServer.SetUserRole = _SetUserRole;
@@ -463,6 +464,11 @@ namespace Vocaluxe.Base.Server
return (from s in songs
select _GetSongInfo(s, false)).ToArray<SSongInfo>();
}
private static string _GetMp3Path(int songId)
{
CSong song = CSongs.GetSong(songId);
return song.GetMP3();
}
private static int _GetCurrentSongId()
{
+1
View File
@@ -231,6 +231,7 @@
<div id="displaySongLinks">
<img class="cursorStyleClickable" id="displaySongAddPlaylist" src="img/addPlaylist.png" />
<br />
<audio controls id="displaySongPlayer" preload="none"></audio>
<br />
<img class="cursorStyleClickable" id="displaySongLinkYoutube" src="img/youtube.png" />
<img class="cursorStyleClickable" id="displaySongLinkSpotify" src="img/spotify.png" />
+7
View File
@@ -1066,6 +1066,13 @@
$('#displaySongIsDuet').text(result.IsDuet ? "Yes" : "No");
if (result.SongId >= 0) {
$('#displaySongPlayer').show()[0].src = "getMp3?songId=" + result.SongId;
} else {
$('#displaySongPlayer').hide();
}
if (result.Title != null || result.Artist != null) {
$('#displaySongLinks').show();