Skip to content

Commit

Permalink
Adding ContentExtensions library.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Mar 14, 2016
1 parent ecca916 commit ed93438
Show file tree
Hide file tree
Showing 12 changed files with 22,399 additions and 0 deletions.
Binary file added Content/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Zoom_launcher.exe
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" 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)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8F7BE148-3922-4979-BA26-9D3145DEB430}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FlatRedBall.ContentExtensions</RootNamespace>
<AssemblyName>ContentExtensions</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="NAudio, Version=1.7.3.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\NAudioRelease\NAudio.dll</HintPath>
</Reference>
<Reference Include="NAudio.WindowsMediaFormat, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\NAudioRelease\NAudio.WindowsMediaFormat.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Encryption\AesEncryptionManager.cs" />
<Compile Include="Loaders\EncryptedTextureLoader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ContentTypes\StreamedSong.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Libraries\NAudioRelease\NAudio.dll" />
<Content Include="Libraries\NAudioRelease\NAudio.WindowsMediaFormat.dll" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
using FlatRedBall.ContentExtensions.Encryption;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FlatRedBall.ContentExtensions.ContentTypes
{
public class StreamedSong : IDisposable
{
Mp3FileReader reader;
WaveOut waveOut;
Stream stream;

public Song XnaSong
{
get;
private set;
}

string customName;

public string Name
{
get
{
if (XnaSong != null)
{
return XnaSong.Name;
}
else
{
return customName;
}
}
}

List<IDisposable> ownedDisposables = new List<IDisposable>();

public bool IsPlaying
{
get
{

return
waveOut != null &&
waveOut.PlaybackState == PlaybackState.Playing;
}
}

float volume = 1;
public float Volume
{
get { return volume; }
set
{
volume = value;
if (waveOut != null)
{
waveOut.Volume = volume;
}
}
}

bool isRepeating;
public bool IsRepeating
{
get
{
return isRepeating;
}
set
{
isRepeating = value;
}
}

public StreamedSong(string xnbFile, ContentManager contentManager)
{
XnaSong = contentManager.Load<Song>(xnbFile);
}

public StreamedSong(string aesEncryptedFileName, string aesKey, string aesInitialVector)
{
var manager = new AesEncryptionManager();
manager.EncryptionKey = aesKey;
manager.InitialVector = aesInitialVector;

using (var encryptedStream = System.IO.File.OpenRead(aesEncryptedFileName))
{
int decryptedSize;
var decryptedBytes = manager.DecryptFromStream(encryptedStream, (int)encryptedStream.Length,
out decryptedSize);

stream = new MemoryStream(decryptedBytes, 0, decryptedSize);

ownedDisposables.Add(stream);
}

this.customName = aesEncryptedFileName;
}

public StreamedSong(Stream stream, string name)
{
this.stream = stream;
this.customName = name;
}

public void Play()
{
if (XnaSong != null)
{
PlayXnaSong();
}
else
{
PlayNAudioSong();
}
}

private void PlayNAudioSong()
{
bool isAlreadyPlaying = waveOut != null;

if (isAlreadyPlaying)
{
throw new InvalidOperationException("Song is already playing");
}

// This makes it behave like XNA - which is crappy, but Baron needs it to behave like XNA for now:
stream.Position = 0;

reader = new Mp3FileReader(stream);
waveOut = new WaveOut();

waveOut.Init(reader);
waveOut.Volume = volume;

waveOut.Play();

waveOut.PlaybackStopped += HandlePlaybackStopped;
}

private void PlayXnaSong()
{
MediaPlayer.Play(XnaSong);
}

private void HandlePlaybackStopped(object sender, StoppedEventArgs e)
{
if (IsRepeating)
{
this.stream.Position = 0;
waveOut.Play();
}
else
{
TryDisposeContainedObjects();
}
}

private void TryDisposeContainedObjects()
{

bool needsToDispose = waveOut != null;

if (needsToDispose)
{
waveOut.Dispose();
reader.Dispose();
waveOut = null;
reader = null;
}
}

public void Stop()
{
TryDisposeContainedObjects();
}

public void Dispose()
{
TryDisposeContainedObjects();
}

}
}
Loading

0 comments on commit ed93438

Please sign in to comment.