Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
iOS: The prototype interface is much better looking now.
iOS: Added album art cover extraction from MP3
Player: Bug fixes for iOS


Related to issue #405.

git-svn-id: http://hamster-svn/svn/repos/base@679 765c1f7c-9fb8-954f-9ff8-dd0915cb3117
  • Loading branch information
animal committed Jan 16, 2013
1 parent 8ced8ec commit 6b27ab8
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 237 deletions.
26 changes: 12 additions & 14 deletions MPfm/branches/current/MPfm.Player/Player.cs
Expand Up @@ -622,6 +622,7 @@ private void Initialize(Device device, int mixerSampleRate, int bufferSize, int
Tracing.Log("Player init -- BASS Mix Version: " + bassMixVersion);

// Check OS type
Console.WriteLine("Player init -- OS is " + OS.Type.ToString());
if (OS.Type == OSType.Linux)
{
string pluginPath = string.Empty;
Expand Down Expand Up @@ -675,26 +676,23 @@ private void Initialize(Device device, int mixerSampleRate, int bufferSize, int
}
else if (OS.Type == OSType.MacOSX)
{
// Find plugins either in current directory (i.e. development) or in a system directory (ex: /usr/lib/mpfm or /opt/lib/mpfm)
string pluginPath = string.Empty;

// Try to get the plugins in the current path
string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

#if DEBUG
pluginPath = exePath;
#else
pluginPath = exePath.Replace("MonoBundle", "Resources");
#endif

#if IOS
// Load decoding plugins (http://www.un4seen.com/forum/?topic=13851.msg96559#msg96559)
Console.WriteLine("Loading iOS plugins (FLAC)...");
flacPluginHandle = Base.LoadPlugin("BASSFLAC");
Console.WriteLine("Loading iOS plugins (WV)...");
wvPluginHandle = Base.LoadPlugin("BASSWV");
Console.WriteLine("Loading iOS plugins (APE)...");
apePluginHandle = Base.LoadPlugin("BASS_APE");
Console.WriteLine("Loading iOS plugins (MPC)...");
mpcPluginHandle = Base.LoadPlugin("BASS_MPC");

#else

// Try to get the plugins in the current path
Console.WriteLine("Loading OS X plugins...");
string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string pluginPath = exePath.Replace("MonoBundle", "Resources");

// Check in the current directory first
if(!File.Exists(pluginPath + "/libbassflac.dylib"))
{
Expand Down Expand Up @@ -1117,7 +1115,7 @@ public void Play()

// Load 18-band equalizer
Tracing.Log("Player.Play -- Creating equalizer (Preset: " + currentEQPreset + ")...");
AddEQ(currentEQPreset);
//AddEQ(currentEQPreset); // TODO: MonoTouch doesn't like the FX implementation

// Check if EQ is bypassed
if (isEQBypassed)
Expand Down
41 changes: 41 additions & 0 deletions MPfm/branches/current/MPfm.Sound/AudioFiles/AudioFile.cs
Expand Up @@ -1449,6 +1449,47 @@ public static Image ExtractImageForAudioFile(string filePath)
}

#endif

/// <summary>
/// Extracts the album art from the audio file. Returns a byte array containing the image.
/// </summary>
/// <param name="filePath">Audio file path</param>
/// <returns>Byte array (image)</returns>
public static byte[] ExtractImageByteArrayForAudioFile(string filePath)
{
byte[] bytes = new byte[0];

// Check if the file exists
if (!File.Exists(filePath))
{
return null;
}

// Check the file extension
string extension = Path.GetExtension(filePath).ToUpper();
if (extension == ".MP3")
{
try
{
// Get tags using TagLib
using (TagLib.Mpeg.AudioFile file = new TagLib.Mpeg.AudioFile(filePath))
{
// Can we get the image from the ID3 tags?
if (file != null && file.Tag != null && file.Tag.Pictures != null && file.Tag.Pictures.Length > 0)
{
// Get image from ID3 tags
bytes = file.Tag.Pictures[0].Data.Data;
}
}
}
catch
{
// Failed to recover album art. Do nothing.
}
}

return bytes;
}
}
}

Expand Up @@ -10,6 +10,7 @@
using System.Timers;
using MPfm.Sound;
using MPfm.Core;
using System.Linq;

namespace MPfm.iOS
{
Expand All @@ -35,9 +36,9 @@ public override void DidReceiveMemoryWarning ()
// Release any cached data, images, etc that aren't in use.
}

public override void ViewDidLoad ()
{
base.ViewDidLoad ();
public override void ViewDidLoad()
{
base.ViewDidLoad();

timer = new Timer();
timer.Interval = 100;
Expand All @@ -50,39 +51,21 @@ public override void ViewDidLoad ()
long ms = ConvertAudio.ToMS(samples, (uint)MPfm.Player.Player.CurrentPlayer.Playlist.CurrentItem.AudioFile.SampleRate);
string pos = Conversion.MillisecondsToTimeString((ulong)ms);
lblPosition.Text = pos + " / " + player.Playlist.CurrentItem.LengthString;
}
catch
sliderPosition.Value = ms;
} catch
{
lblPosition.Text = "Error";
lblPosition.Text = "0:00.000";
}
});
};

// Perform any additional setup after loading the view, typically from a nib.
Device device = new Device(){
// Initialize player
Device device = new Device(){
DriverType = DriverType.DirectSound,
Id = -1
};
string test = BassWrapperGlobals.DllImportValue_Bass;
player = new MPfm.Player.Player(device, 44100, 5000, 100, true);
string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string path2 = NSBundle.MainBundle.BundlePath;
string filePath = Path.Combine(path2, "01.flac");
string filePath2 = Path.Combine(path2, "02.flac");
string filePath3 = Path.Combine(path2, "03.flac");
string filePath4 = Path.Combine(path2, "04.flac");
string filePath5 = Path.Combine(path2, "05.flac");
string filePath6 = Path.Combine(path2, "06.flac");
//filePath = filePath.Replace("/Documents", "");
bool exists = File.Exists(filePath);
player.PlayFiles(new List<string> { filePath, filePath2, filePath3, filePath4, filePath5, filePath6 });
player.OnPlaylistIndexChanged += (data) => {
InvokeOnMainThread(() => {
RefreshAudioFile(data.AudioFileStarted);
});
};
timer.Start();
RefreshAudioFile(player.Playlist.CurrentItem.AudioFile);
player = new MPfm.Player.Player(device, 44100, 5000, 100, true);
Play();
}

public override void ViewDidUnload ()
Expand All @@ -109,9 +92,47 @@ public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientat

private void RefreshAudioFile(AudioFile audioFile)
{
lblArtistName.Text = audioFile.ArtistName;
lblAlbumTitle.Text = audioFile.AlbumTitle;
lblTitle.Text = audioFile.Title;
InvokeOnMainThread(() => {
byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath);
NSData imageData = NSData.FromArray(bytesImage);
UIImage image = UIImage.LoadFromData(imageData);
lblArtistName.Text = audioFile.ArtistName;
lblAlbumTitle.Text = audioFile.AlbumTitle;
lblTitle.Text = audioFile.Title;
imageViewAlbumArt.Image = image;
sliderPosition.MaxValue = player.Playlist.CurrentItem.LengthMilliseconds;
});
}

private void Play()
{
// Add files to play
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
List<string> listFiles = Directory.EnumerateFiles(documentsPath).ToList();

if (listFiles.Count > 0)
{
player.PlayFiles(listFiles);
}
else
{
string path2 = NSBundle.MainBundle.BundlePath;
string filePath = Path.Combine(path2, "01.mp3");
string filePath2 = Path.Combine(path2, "02.mp3");
string filePath3 = Path.Combine(path2, "03.mp3");
string filePath4 = Path.Combine(path2, "04.mp3");
string filePath5 = Path.Combine(path2, "05.mp3");
player.PlayFiles(new List<string> { filePath, filePath2, filePath3, filePath4, filePath5 });
}

player.OnPlaylistIndexChanged += (data) => {
RefreshAudioFile(data.AudioFileStarted);
};
timer.Start();
RefreshAudioFile(player.Playlist.CurrentItem.AudioFile);
}

partial void actionPlay(NSObject sender)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions MPfm/branches/current/MPfm.iOS/MPfm.iOS.csproj
Expand Up @@ -68,6 +68,7 @@
<MtouchExtraArgs>-v -v -v -gcc_flags "-L${ProjectDir}/Lib/ -framework Accelerate -ObjC -lstdc++ -lbass -lbassmix -lbass_fx -lbass_ape -lbass_mpc -lbassflac -lbasswv -all_load"</MtouchExtraArgs>
<MtouchI18n />
<MtouchArch>ARMv7</MtouchArch>
<IpaPackageName />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' ">
<DebugType>none</DebugType>
Expand Down

0 comments on commit 6b27ab8

Please sign in to comment.