Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
cadahl committed Oct 22, 2011
2 parents 926a3f8 + 9e02eb8 commit b92c095
Show file tree
Hide file tree
Showing 44 changed files with 2,560 additions and 2,294 deletions.
31 changes: 31 additions & 0 deletions MonoGame.Framework/Android/AndroidGameActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace Microsoft.Xna.Framework
{
public class AndroidGameActivity : Activity
{
public Game Game { get; set; }

protected override void OnPause()
{
base.OnPause();
if (Game != null) Game.EnterBackground();
}

protected override void OnResume()
{
base.OnResume();
if (Game != null) Game.EnterForeground();
}
}
}
72 changes: 51 additions & 21 deletions MonoGame.Framework/Android/Audio/Sound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
using Android.Util;
using Android.Views;
using Android.Widget;
using Android.Content.Res;

namespace Microsoft.Xna.Framework.Audio
{
public class Sound
internal class Sound : IDisposable
{
internal MediaPlayer _player;
private float _Volume;
Expand Down Expand Up @@ -50,9 +51,9 @@ private static void Worker(object state)
{
workItem();
}
catch
catch(Exception ex)
{
Log.Debug("Sound.Worker" , "Sound thread: Work Exception");
Log.Debug("Sound.Worker" , "Sound thread: Work Exception" + ex.ToString());
}
}
}
Expand All @@ -67,6 +68,11 @@ private Sound(MediaPlayer player)
_player = player;
}

~Sound()
{
Dispose();
}

public void Dispose()
{
_player.Dispose();
Expand All @@ -86,6 +92,22 @@ public float Volume
}
}

public double Duration
{
get
{
return _player != null ? _player.Duration : 0;
}
}

public double CurrentPosition
{
get
{
return _player != null ? _player.CurrentPosition : 0;
}
}

public bool Looping
{
get { return this._Looping; }
Expand All @@ -108,6 +130,7 @@ public void Play()
if (this._player == null)
return;

//_player.Start();
Sound.Enqueue(_player.Start);
}

Expand Down Expand Up @@ -152,28 +175,35 @@ protected void OnPrepared(object sender, EventArgs e)
IsPrepared = true;
}

public static Sound Create(string assetPath, float volume, bool looping)



public Sound(string filename, float volume, bool looping)
{
MediaPlayer player = new MediaPlayer();
Sound sound = new Sound(player);
//This breaks the platformer sample. Not sure if it works anywhere else
//player.SetDataSource(Game.contextInstance.Assets.OpenFd(assetPath).FileDescriptor);
player.SetDataSource(assetPath);
player.Prepared += sound.OnPrepared;
sound.Looping = looping;
sound.Volume = volume;

Sound.Enqueue(player.Prepare);

return sound;
this._player = new MediaPlayer();
// get the Asset Descriptor and Release it when the SetDataSource returns
// otherwise you cant play the file
using (AssetFileDescriptor fd = Game.contextInstance.Assets.OpenFd(filename))
{
_player.SetDataSource(fd.FileDescriptor);
}
_player.Prepared += this.OnPrepared;
this.Looping = looping;
this.Volume = volume;
// prepare on the background thread
try
{
_player.PrepareAsync();
}
catch (Exception ex)
{
Log.Debug("MonoGameInfo", ex.ToString());
}
}

public static Sound CreateAndPlay(string url, float volume, bool looping)
public Sound(byte[] audiodata, float volume, bool looping)
{
Sound sound = Sound.Create(url, volume, looping);
sound.Play();

return sound;
throw new NotImplementedException();
}

}
Expand Down
109 changes: 0 additions & 109 deletions MonoGame.Framework/Android/Audio/SoundEffect.cs

This file was deleted.

Loading

0 comments on commit b92c095

Please sign in to comment.