Added preview-player which is used for playing preview in song-menu.

This commit is contained in:
Florian Küpper committed 2014-08-09 17:12:27 +02:00
1 parent bd41de6dbe
commit 4c01396e46
10 files changed
+163 -47

No files matched your search

+2
View File
@@ -263,6 +263,8 @@ namespace Vocaluxe.Base
xmlReader.TryGetEnumValue("//root/Sound/BackgroundMusicUseStart", ref BackgroundMusicUseStart); xmlReader.TryGetEnumValue("//root/Sound/BackgroundMusicUseStart", ref BackgroundMusicUseStart);
xmlReader.TryGetIntValueRange("//root/Sound/PreviewMusicVolume", ref _PreviewMusicVolume); xmlReader.TryGetIntValueRange("//root/Sound/PreviewMusicVolume", ref _PreviewMusicVolume);
xmlReader.TryGetIntValueRange("//root/Sound/GameMusicVolume", ref _GameMusicVolume); xmlReader.TryGetIntValueRange("//root/Sound/GameMusicVolume", ref _GameMusicVolume);
CPreviewPlayer.UpdateVolume();
#endregion Sound #endregion Sound
#region Game #region Game
+45 -1
View File
@@ -51,11 +51,12 @@ namespace Vocaluxe.Base
private static readonly IDataBase _DataBase = new CBdataBase(); private static readonly IDataBase _DataBase = new CBdataBase();
private static readonly IControllers _Controller = new CBcontrollers(); private static readonly IControllers _Controller = new CBcontrollers();
private static readonly IPlaylist _Playlist = new CBplaylist(); private static readonly IPlaylist _Playlist = new CBplaylist();
private static readonly IPreviewPlayer _PreviewPlayer = new CBpreviewPlayer();
public static void Init() public static void Init()
{ {
CBase.Assign(_Config, _Settings, _Theme, _Log, _BackgroundMusic, _Draw, _Graphics, _Fonts, _Language, CBase.Assign(_Config, _Settings, _Theme, _Log, _BackgroundMusic, _Draw, _Graphics, _Fonts, _Language,
_Game, _Profiles, _Record, _Songs, _Video, _Sound, _Cover, _DataBase, _Controller, _Playlist); _Game, _Profiles, _Record, _Songs, _Video, _Sound, _Cover, _DataBase, _Controller, _Playlist, _PreviewPlayer);
} }
} }
@@ -960,4 +961,47 @@ namespace Vocaluxe.Base
return CPlaylists.GetSong(playlistID, songIndex); return CPlaylists.GetSong(playlistID, songIndex);
} }
} }
class CBpreviewPlayer : IPreviewPlayer
{
public void Play(float start = -1)
{
CPreviewPlayer.Play();
}
public void Load(CSong song, float start = 0f)
{
CPreviewPlayer.Load(song, start);
}
public void Stop()
{
CPreviewPlayer.Stop();
}
public void Pause()
{
CPreviewPlayer.Pause();
}
public CTexture GetCover()
{
return CPreviewPlayer.Cover;
}
public CTexture GetVideoTexture()
{
return CPreviewPlayer.VideoTexture;
}
public bool IsPlaying()
{
return CPreviewPlayer.IsPlaying;
}
public float GetLength()
{
return CPreviewPlayer.Length;
}
}
} }
+69
View File
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VocaluxeLib.Utils.Player;
using VocaluxeLib.Draw;
using VocaluxeLib.Songs;
namespace Vocaluxe.Base
{
public static class CPreviewPlayer
{
private static CSongPlayer _Player = new CSongPlayer(true);
public static CTexture VideoTexture
{
get { return _Player.GetVideoTexture(); }
}
public static CTexture Cover
{
get { return _Player.Cover; }
}
public static bool IsPlaying
{
get { return _Player.IsPlaying; }
}
public static float Length
{
get { return _Player.Length; }
}
public static void Load(CSong song, float start = 0f)
{
if (song == null)
return;
if (start == 0f)
start = song.Preview.StartTime;
_Player.Load(song, start);
}
public static void Play(float start = -1)
{
if (start > -1)
_Player.Position = start;
_Player.Play();
}
public static void Pause()
{
_Player.TogglePause();
}
public static void Stop()
{
_Player.Stop();
}
public static void UpdateVolume()
{
_Player.Volume = CConfig.PreviewMusicVolume;
}
}
}
+1
View File
@@ -217,6 +217,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Base\CBackgroundMusic.cs" /> <Compile Include="Base\CBackgroundMusic.cs" />
<Compile Include="Base\CPlaylistElement.cs" /> <Compile Include="Base\CPlaylistElement.cs" />
<Compile Include="Base\CPreviewPlayer.cs" />
<Compile Include="Base\CRecord.cs" /> <Compile Include="Base\CRecord.cs" />
<Compile Include="COSFunctions.cs" /> <Compile Include="COSFunctions.cs" />
<Compile Include="Lib\Database\CCoverDB.cs" /> <Compile Include="Lib\Database\CCoverDB.cs" />
+4 -1
View File
@@ -38,10 +38,12 @@ namespace VocaluxeLib
public static IDataBase DataBase; public static IDataBase DataBase;
public static IControllers Controller; public static IControllers Controller;
public static IPlaylist Playlist; public static IPlaylist Playlist;
public static IPreviewPlayer PreviewPlayer;
public static void Assign(IConfig config, ISettings settings, ITheme theme, ILog log, IBackgroundMusic backgroundMusic, public static void Assign(IConfig config, ISettings settings, ITheme theme, ILog log, IBackgroundMusic backgroundMusic,
IDrawing draw, IGraphics graphics, IFonts fonts, ILanguage language, IGame game, IProfiles profiles, IRecording record, IDrawing draw, IGraphics graphics, IFonts fonts, ILanguage language, IGame game, IProfiles profiles, IRecording record,
ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IControllers controller, IPlaylist playlist) ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IControllers controller, IPlaylist playlist,
IPreviewPlayer previewPlayer)
{ {
Config = config; Config = config;
Settings = settings; Settings = settings;
@@ -62,6 +64,7 @@ namespace VocaluxeLib
DataBase = dataBase; DataBase = dataBase;
Controller = controller; Controller = controller;
Playlist = playlist; Playlist = playlist;
PreviewPlayer = previewPlayer;
} }
} }
} }
+13
View File
@@ -315,4 +315,17 @@ namespace VocaluxeLib
int GetSongCount(int playlistID); int GetSongCount(int playlistID);
CPlaylistSong GetSong(int playlistID, int songIndex); CPlaylistSong GetSong(int playlistID, int songIndex);
} }
public interface IPreviewPlayer
{
void Play(float start = -1);
void Load(CSong song, float start = 0f);
void Stop();
void Pause();
CTexture GetCover();
CTexture GetVideoTexture();
bool IsPlaying();
float GetLength();
}
} }
@@ -121,12 +121,6 @@ namespace VocaluxeLib.Menu.SongMenu
} }
} }
protected int _PreviewSongStream { get; private set; }
protected int _PreviewVideoStream { get; private set; }
private CFading _VideoFading;
protected CTexture _Vidtex;
private SColorF _ColorInternal; private SColorF _ColorInternal;
protected SColorF _Color protected SColorF _Color
{ {
@@ -160,8 +154,6 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
Visible = true; Visible = true;
_PartyModeID = partyModeID; _PartyModeID = partyModeID;
_PreviewVideoStream = -1;
_PreviewSongStream = -1;
_Theme = new SThemeSongMenu _Theme = new SThemeSongMenu
{ {
SongMenuTileBoard = SongMenuTileBoard =
@@ -354,7 +346,7 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
if (!_Initialized) if (!_Initialized)
return; return;
/*
if (_PreviewSongStream == -1 || _PreviewVideoStream == -1) if (_PreviewSongStream == -1 || _PreviewVideoStream == -1)
return; return;
@@ -380,7 +372,7 @@ namespace VocaluxeLib.Menu.SongMenu
_VideoFading = null; _VideoFading = null;
} }
} }
} }*/
} }
public virtual void OnShow() {} public virtual void OnShow() {}
@@ -399,8 +391,8 @@ namespace VocaluxeLib.Menu.SongMenu
if (!_Initialized || !Visible) if (!_Initialized || !Visible)
return; return;
if (_PreviewVideoStream != -1) if (CBase.PreviewPlayer.IsPlaying())
CBase.Drawing.DrawTexture(_Vidtex, new SRectF(0, 0, 1280, 720, 0)); CBase.Drawing.DrawTexture(CBase.PreviewPlayer.GetVideoTexture(), new SRectF(0, 0, 1280, 720, 0));
} }
public bool IsMouseOverSelectedSong(SMouseEvent mEvent) public bool IsMouseOverSelectedSong(SMouseEvent mEvent)
@@ -509,44 +501,23 @@ namespace VocaluxeLib.Menu.SongMenu
if (song == null) if (song == null)
return; return;
//TODO: Using prescan here causes Vocaluxe to hang a bit on loading the song but we need the length below CBase.PreviewPlayer.Load(song);
_PreviewSongStream = CBase.Sound.Load(Path.Combine(song.Folder, song.MP3FileName), true, true);
float startposition = song.Preview.StartTime; float startposition = song.Preview.StartTime;
float length = CBase.Sound.GetLength(_PreviewSongStream);
float length = CBase.PreviewPlayer.GetLength();
if (song.Preview.Source == EDataSource.None) if (song.Preview.Source == EDataSource.None)
startposition = length / 4f; startposition = length / 4f;
else if (startposition > length - 5f) else if (startposition > length - 5f)
startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f)); startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f));
CBase.Sound.SetPosition(_PreviewSongStream, startposition); CBase.PreviewPlayer.Play(startposition);
CBase.Sound.Play(_PreviewSongStream);
CBase.Sound.SetStreamVolume(_PreviewSongStream, 0f);
CBase.Sound.Fade(_PreviewSongStream, 100f, 3f);
if (song.VideoFileName != "" && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON)
{
_PreviewVideoStream = CBase.Video.Load(Path.Combine(song.Folder, song.VideoFileName));
if (_PreviewVideoStream == -1)
return;
CBase.Video.SetLoop(_PreviewVideoStream);
CBase.Video.Skip(_PreviewVideoStream, startposition, song.VideoGap);
_VideoFading = new CFading(0f, 1f, 3f);
}
} }
protected void _ResetPreview() protected void _ResetPreview()
{ {
if (_PreviewSongStream >= 0) CBase.PreviewPlayer.Stop();
CBase.Sound.Fade(_PreviewSongStream, 0f, 0.75f, EStreamAction.Close);
_PreviewSongStream = -1;
CBase.Video.Close(_PreviewVideoStream);
_PreviewVideoStream = -1;
CBase.Drawing.RemoveTexture(ref _Vidtex);
} }
#region ThemeEdit #region ThemeEdit
@@ -179,7 +179,7 @@ namespace VocaluxeLib.Menu.SongMenu
if (songOptions.Selection.RandomOnly) if (songOptions.Selection.RandomOnly)
_PreviewNr = _SelectionNr; _PreviewNr = _SelectionNr;
if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.Sound.GetLength(_PreviewSongStream) > 0) if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.PreviewPlayer.GetLength() > 0)
_UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr)); _UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr));
} }
@@ -244,7 +244,7 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
if (song == null) if (song == null)
return; return;
float time = CBase.Sound.GetLength(_PreviewSongStream); float time = CBase.PreviewPlayer.GetLength();
if (Math.Abs(song.Finish) > 0.001) if (Math.Abs(song.Finish) > 0.001)
time = song.Finish; time = song.Finish;
@@ -462,18 +462,20 @@ namespace VocaluxeLib.Menu.SongMenu
_TextBG.Draw(); _TextBG.Draw();
if (_Vidtex != null && _PreviewVideoStream != -1) CTexture vidtex = CBase.PreviewPlayer.GetVideoTexture();
if (vidtex != null)
{ {
if (_Vidtex.Color.A < 1) if (vidtex.Color.A < 1)
_CoverBig.Draw(EAspect.Crop); _CoverBig.Draw(EAspect.Crop);
var bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H); var bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H);
RectangleF rect; RectangleF rect;
CHelper.SetRect(bounds, out rect, _Vidtex.OrigAspect, EAspect.Crop); CHelper.SetRect(bounds, out rect, vidtex.OrigAspect, EAspect.Crop);
var vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z); var vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z);
var vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f); var vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f);
CBase.Drawing.DrawTexture(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds); CBase.Drawing.DrawTexture(vidtex, vidRect, vidtex.Color, vidRectBounds);
CBase.Drawing.DrawTextureReflection(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight); CBase.Drawing.DrawTextureReflection(vidtex, vidRect, vidtex.Color, vidRectBounds, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight);
} }
else else
_CoverBig.Draw(EAspect.Crop); _CoverBig.Draw(EAspect.Crop);
+10
View File
@@ -38,6 +38,16 @@ namespace VocaluxeLib.Utils.Player
} }
} }
public float Length
{
get
{
if (_StreamID == -1)
return 0;
return CBase.Sound.GetLength(_StreamID);
}
}
public bool RepeatSong; public bool RepeatSong;
public bool IsPlaying { get; private set; } public bool IsPlaying { get; private set; }
+1
View File
@@ -135,6 +135,7 @@
<Compile Include="PartyModes\IPartyMode.cs" /> <Compile Include="PartyModes\IPartyMode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\CWavFile.cs" /> <Compile Include="Utils\CWavFile.cs" />
<Compile Include="Utils\Player\CPreviewPlayer.cs" />
<Compile Include="Utils\Player\CSongPlayer.cs" /> <Compile Include="Utils\Player\CSongPlayer.cs" />
<Compile Include="Utils\Player\CSoundPlayer.cs" /> <Compile Include="Utils\Player\CSoundPlayer.cs" />
</ItemGroup> </ItemGroup>