From 6e59dfddcc4382bbdff23c84e26e34d753b90edc Mon Sep 17 00:00:00 2001 From: chylex <contact@chylex.com> Date: Sat, 13 Jan 2018 23:38:30 +0100 Subject: [PATCH] Remove audio library --- TweetDuck.sln | 6 - bld/gen_upd.iss | 1 + lib/TweetLib.Audio/AudioPlayer.cs | 41 ------ .../Impl/SoundPlayerImplFallback.cs | 53 -------- lib/TweetLib.Audio/Impl/SoundPlayerImplWMP.cs | 124 ------------------ lib/TweetLib.Audio/PlaybackErrorEventArgs.cs | 13 -- lib/TweetLib.Audio/Properties/AssemblyInfo.cs | 35 ----- lib/TweetLib.Audio/TweetLib.Audio.csproj | 50 ------- 8 files changed, 1 insertion(+), 322 deletions(-) delete mode 100644 lib/TweetLib.Audio/AudioPlayer.cs delete mode 100644 lib/TweetLib.Audio/Impl/SoundPlayerImplFallback.cs delete mode 100644 lib/TweetLib.Audio/Impl/SoundPlayerImplWMP.cs delete mode 100644 lib/TweetLib.Audio/PlaybackErrorEventArgs.cs delete mode 100644 lib/TweetLib.Audio/Properties/AssemblyInfo.cs delete mode 100644 lib/TweetLib.Audio/TweetLib.Audio.csproj diff --git a/TweetDuck.sln b/TweetDuck.sln index 95c0b692..f4155fbc 100644 --- a/TweetDuck.sln +++ b/TweetDuck.sln @@ -8,8 +8,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetDuck.Browser", "subpro EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "tests\UnitTests.csproj", "{A958FA7A-4A2C-42A7-BFA0-159343483F4E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetLib.Audio", "lib\TweetLib.Audio\TweetLib.Audio.csproj", "{E9E1FD1B-F480-45B7-9970-BE2ECFD309AC}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetDuck.Video", "video\TweetDuck.Video.csproj", "{278B2D11-402D-44B6-B6A1-8FA67DB65565}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetLib.Communication", "lib\TweetLib.Communication\TweetLib.Communication.csproj", "{72473763-4B9D-4FB6-A923-9364B2680F06}" @@ -32,10 +30,6 @@ Global {A958FA7A-4A2C-42A7-BFA0-159343483F4E}.Debug|x86.ActiveCfg = Debug|x86 {A958FA7A-4A2C-42A7-BFA0-159343483F4E}.Debug|x86.Build.0 = Debug|x86 {A958FA7A-4A2C-42A7-BFA0-159343483F4E}.Release|x86.ActiveCfg = Release|x86 - {E9E1FD1B-F480-45B7-9970-BE2ECFD309AC}.Debug|x86.ActiveCfg = Debug|x86 - {E9E1FD1B-F480-45B7-9970-BE2ECFD309AC}.Debug|x86.Build.0 = Debug|x86 - {E9E1FD1B-F480-45B7-9970-BE2ECFD309AC}.Release|x86.ActiveCfg = Release|x86 - {E9E1FD1B-F480-45B7-9970-BE2ECFD309AC}.Release|x86.Build.0 = Release|x86 {278B2D11-402D-44B6-B6A1-8FA67DB65565}.Debug|x86.ActiveCfg = Debug|x86 {278B2D11-402D-44B6-B6A1-8FA67DB65565}.Debug|x86.Build.0 = Debug|x86 {278B2D11-402D-44B6-B6A1-8FA67DB65565}.Release|x86.ActiveCfg = Release|x86 diff --git a/bld/gen_upd.iss b/bld/gen_upd.iss index fa3b0d18..eba60747 100644 --- a/bld/gen_upd.iss +++ b/bld/gen_upd.iss @@ -59,6 +59,7 @@ Type: filesandordirs; Name: "{localappdata}\{#MyAppName}\Cache" Type: filesandordirs; Name: "{localappdata}\{#MyAppName}\GPUCache" [InstallDelete] +Type: files; Name: "{app}\TweetLib.Audio.dll" Type: filesandordirs; Name: "{app}\plugins\official" Type: files; Name: "{app}\locales\am.pak" Type: files; Name: "{app}\locales\ar.pak" diff --git a/lib/TweetLib.Audio/AudioPlayer.cs b/lib/TweetLib.Audio/AudioPlayer.cs deleted file mode 100644 index 29879ec8..00000000 --- a/lib/TweetLib.Audio/AudioPlayer.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using TweetLib.Audio.Impl; - -namespace TweetLib.Audio{ - public abstract class AudioPlayer : IDisposable{ - private static bool? IsWMPAvailable; - - public static AudioPlayer New(){ - if (IsWMPAvailable.HasValue){ - if (IsWMPAvailable.Value){ - return new SoundPlayerImplWMP(); - } - else{ - return new SoundPlayerImplFallback(); - } - } - - try{ - SoundPlayerImplWMP implWMP = new SoundPlayerImplWMP(); - IsWMPAvailable = true; - return implWMP; - }catch(COMException){ - IsWMPAvailable = false; - return new SoundPlayerImplFallback(); - } - } - - public abstract string SupportedFormats { get; } - public abstract event EventHandler<PlaybackErrorEventArgs> PlaybackError; - - public abstract void Play(string file); - public abstract bool SetVolume(int volume); - protected abstract void Dispose(bool disposing); - - public void Dispose(){ - Dispose(true); - GC.SuppressFinalize(this); - } - } -} diff --git a/lib/TweetLib.Audio/Impl/SoundPlayerImplFallback.cs b/lib/TweetLib.Audio/Impl/SoundPlayerImplFallback.cs deleted file mode 100644 index e13021ce..00000000 --- a/lib/TweetLib.Audio/Impl/SoundPlayerImplFallback.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.IO; -using System.Media; - -namespace TweetLib.Audio.Impl{ - sealed class SoundPlayerImplFallback : AudioPlayer{ - public override string SupportedFormats => "*.wav"; - - public override event EventHandler<PlaybackErrorEventArgs> PlaybackError; - - private readonly SoundPlayer player; - private bool ignorePlaybackError; - - public SoundPlayerImplFallback(){ - player = new SoundPlayer{ - LoadTimeout = 5000 - }; - } - - public override void Play(string file){ - if (player.SoundLocation != file){ - player.SoundLocation = file; - ignorePlaybackError = false; - } - - try{ - player.Play(); - }catch(FileNotFoundException e){ - OnNotificationSoundError("File not found: "+e.FileName); - }catch(InvalidOperationException){ - OnNotificationSoundError("File format was not recognized."); - }catch(TimeoutException){ - OnNotificationSoundError("File took too long to load."); - } - } - - public override bool SetVolume(int volume){ - return false; - } - - protected override void Dispose(bool disposing){ - player.Dispose(); - } - - private void OnNotificationSoundError(string message){ - if (!ignorePlaybackError){ - PlaybackErrorEventArgs args = new PlaybackErrorEventArgs(message); - PlaybackError?.Invoke(this, args); - ignorePlaybackError = args.Ignore; - } - } - } -} diff --git a/lib/TweetLib.Audio/Impl/SoundPlayerImplWMP.cs b/lib/TweetLib.Audio/Impl/SoundPlayerImplWMP.cs deleted file mode 100644 index b68376aa..00000000 --- a/lib/TweetLib.Audio/Impl/SoundPlayerImplWMP.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Windows.Forms; -using WMPLib; - -namespace TweetLib.Audio.Impl{ - sealed class SoundPlayerImplWMP : AudioPlayer{ - public override string SupportedFormats => "*.wav;*.mp3;*.mp2;*.m4a;*.mid;*.midi;*.rmi;*.wma;*.aif;*.aifc;*.aiff;*.snd;*.au"; - - public override event EventHandler<PlaybackErrorEventArgs> PlaybackError; - - private readonly Form owner; - private readonly ControlWMP wmp; - private bool wasTryingToPlay; - private bool ignorePlaybackError; - - private WindowsMediaPlayer Player => wmp.Ocx; - - public SoundPlayerImplWMP(){ - owner = new Form(); - wmp = new ControlWMP(); - wmp.BeginInit(); - owner.Controls.Add(wmp); - wmp.EndInit(); - - Player.uiMode = "none"; - Player.settings.autoStart = false; - Player.settings.enableErrorDialogs = false; - Player.settings.invokeURLs = false; - Player.settings.volume = 0; - Player.MediaChange += player_MediaChange; - Player.MediaError += player_MediaError; - } - - public override void Play(string file){ - wasTryingToPlay = true; - - try{ - if (Player.URL != file){ - Player.close(); - Player.URL = file; - ignorePlaybackError = false; - } - else{ - Player.controls.stop(); - } - - Player.controls.play(); - }catch(Exception e){ - OnNotificationSoundError("An error occurred in Windows Media Player: "+e.Message); - } - } - - public override bool SetVolume(int volume){ - Player.settings.volume = volume; - return true; - } - - protected override void Dispose(bool disposing){ - wmp.Dispose(); - owner.Dispose(); - } - - private void player_MediaChange(object item){ - IWMPMedia2 media = item as IWMPMedia2; - - if (media == null){ - OnNotificationSoundError("Unknown error."); - return; - } - // ReSharper disable once CompareOfFloatsByEqualityOperator - else if (media.Error == null && media.duration == 0.0){ - OnNotificationSoundError("File does not contain an audio track."); - } - else if (media.Error != null){ - OnNotificationSoundError(media.Error); - } - - Marshal.ReleaseComObject(media); - } - - private void player_MediaError(object pMediaObject){ - IWMPMedia2 media = pMediaObject as IWMPMedia2; - - if (media == null){ - OnNotificationSoundError("Unknown error."); - return; - } - else if (media.Error != null){ - OnNotificationSoundError(media.Error); - } - - Marshal.ReleaseComObject(media); - } - - private void OnNotificationSoundError(IWMPErrorItem error){ - OnNotificationSoundError(error.errorCode == -1072885353 ? "Invalid media file." : error.errorDescription); - Marshal.ReleaseComObject(error); - } - - private void OnNotificationSoundError(string message){ - if (wasTryingToPlay){ - wasTryingToPlay = false; - - if (!ignorePlaybackError){ - PlaybackErrorEventArgs args = new PlaybackErrorEventArgs(message); - PlaybackError?.Invoke(this, args); - ignorePlaybackError = args.Ignore; - } - } - } - - [Clsid("{6bf52a52-394a-11d3-b153-00c04f79faa6}")] - private sealed class ControlWMP : AxHost{ - public WindowsMediaPlayer Ocx { get; private set; } - - public ControlWMP() : base("6bf52a52-394a-11d3-b153-00c04f79faa6"){} - - protected override void AttachInterfaces(){ - Ocx = (WindowsMediaPlayer)GetOcx(); - } - } - } -} diff --git a/lib/TweetLib.Audio/PlaybackErrorEventArgs.cs b/lib/TweetLib.Audio/PlaybackErrorEventArgs.cs deleted file mode 100644 index f8f07325..00000000 --- a/lib/TweetLib.Audio/PlaybackErrorEventArgs.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace TweetLib.Audio{ - public sealed class PlaybackErrorEventArgs : EventArgs{ - public string Message { get; } - public bool Ignore { get; set; } - - public PlaybackErrorEventArgs(string message){ - this.Message = message; - this.Ignore = false; - } - } -} diff --git a/lib/TweetLib.Audio/Properties/AssemblyInfo.cs b/lib/TweetLib.Audio/Properties/AssemblyInfo.cs deleted file mode 100644 index c38326d2..00000000 --- a/lib/TweetLib.Audio/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("TweetDuck Audio Library")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("TweetDuck Audio Library")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("e9e1fd1b-f480-45b7-9970-be2ecfd309ac")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.1.0")] -[assembly: AssemblyFileVersion("1.1.1.0")] diff --git a/lib/TweetLib.Audio/TweetLib.Audio.csproj b/lib/TweetLib.Audio/TweetLib.Audio.csproj deleted file mode 100644 index 69adb783..00000000 --- a/lib/TweetLib.Audio/TweetLib.Audio.csproj +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">x86</Platform> - <ProjectGuid>{E9E1FD1B-F480-45B7-9970-BE2ECFD309AC}</ProjectGuid> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>TweetLib.Audio</RootNamespace> - <AssemblyName>TweetLib.Audio</AssemblyName> - <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - <ResolveComReferenceSilent>True</ResolveComReferenceSilent> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> - <PlatformTarget>x86</PlatformTarget> - <OutputPath>bin\x86\Debug\</OutputPath> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> - <PlatformTarget>x86</PlatformTarget> - <OutputPath>bin\x86\Release\</OutputPath> - <Optimize>true</Optimize> - </PropertyGroup> - <ItemGroup> - <Reference Include="System" /> - <Reference Include="System.Core" /> - <Reference Include="Microsoft.CSharp" /> - <Reference Include="System.Windows.Forms" /> - </ItemGroup> - <ItemGroup> - <Compile Include="AudioPlayer.cs" /> - <Compile Include="PlaybackErrorEventArgs.cs" /> - <Compile Include="Impl\SoundPlayerImplFallback.cs" /> - <Compile Include="Impl\SoundPlayerImplWMP.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - </ItemGroup> - <ItemGroup> - <COMReference Include="WMPLib"> - <Guid>{6BF52A50-394A-11D3-B153-00C04F79FAA6}</Guid> - <VersionMajor>1</VersionMajor> - <VersionMinor>0</VersionMinor> - <Lcid>0</Lcid> - <WrapperTool>tlbimp</WrapperTool> - <Isolated>False</Isolated> - <EmbedInteropTypes>True</EmbedInteropTypes> - </COMReference> - </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -</Project> \ No newline at end of file