static AudioService() { var alarmPath = P42.Utils.EmbeddedResourceCache.LocalStorageFullPathForEmbeddedResource("Forms9Patch.Resources.Sounds.alarm.mp3", typeof(Forms9Patch.Feedback).Assembly); var alertPath = P42.Utils.EmbeddedResourceCache.LocalStorageFullPathForEmbeddedResource("Forms9Patch.Resources.Sounds.alert.mp3", typeof(Forms9Patch.Feedback).Assembly); var errorPath = P42.Utils.EmbeddedResourceCache.LocalStorageFullPathForEmbeddedResource("Forms9Patch.Resources.Sounds.error.mp3", typeof(Forms9Patch.Feedback).Assembly); var messagePath = P42.Utils.EmbeddedResourceCache.LocalStorageFullPathForEmbeddedResource("Forms9Patch.Resources.Sounds.message.mp3", typeof(Forms9Patch.Feedback).Assembly); var notificationPath = P42.Utils.EmbeddedResourceCache.LocalStorageFullPathForEmbeddedResource("Forms9Patch.Resources.Sounds.notification.mp3", typeof(Forms9Patch.Feedback).Assembly); alarmPlayer = new AVFoundation.AVAudioPlayer(NSUrl.FromFilename(alarmPath), "mp3", out NSError nSError0); alertPlayer = new AVFoundation.AVAudioPlayer(NSUrl.FromFilename(alertPath), "mp3", out NSError nSError1); errorPlayer = new AVFoundation.AVAudioPlayer(NSUrl.FromFilename(errorPath), "mp3", out NSError nSError2); messagePlayer = new AVFoundation.AVAudioPlayer(NSUrl.FromFilename(messagePath), "mp3", out NSError nSError3); notificationPlayer = new AVFoundation.AVAudioPlayer(NSUrl.FromFilename(notificationPath), "mp3", out NSError nSError4); }
public void Play(string folder, string filename) { try { string file = System.IO.Path.Combine("Music", filename); Foundation.NSUrl Soundurl = Foundation.NSUrl.FromFilename(file); player = AVFoundation.AVAudioPlayer.FromUrl(Soundurl); player.CurrentTime = player.Duration * 2; player.NumberOfLoops = 1; player.Volume = 1.0f; player.FinishedPlaying += DidFinishPlaying; player.PrepareToPlay(); player.Play(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("PlaySound: Error: " + e.Message, true); } }
public MusicPlayer(string name, string type) { var backgroundMusicPath = new NSUrl(NSBundle.MainBundle.PathForResource(name, type)); aVAudioPlayer = AVFoundation.AVAudioPlayer.FromUrl(backgroundMusicPath, out NSError error); }