Skip to content

Xamarin - [iOS] How to play an MP3 / WAV using AVAudioPlayer

Notifications You must be signed in to change notification settings

mattregul/iOSPlayAudioClip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iOSPlayAudioClip

Xamarin - [iOS] How to play an MP3 / WAV using AVAudioPlayer

using System;
using AVFoundation;
using Foundation;
using UIKit;

namespace iOSPlayAudioClip
{
	public partial class ViewController : UIViewController
	{

		AVAudioPlayer _player;
		NSError error;

		protected ViewController(IntPtr handle) : base(handle)
		{
			// Note: this .ctor should not contain any initialization logic.
		}

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


			// WAV File ================================================================
			// Sound from  http://opengameart.org/content/warp-sound-2
			_player = new AVAudioPlayer(NSUrl.FromFilename("wave2.wav"), "wav", out error)
			{
				Volume = 2,
				NumberOfLoops = -1 // Loop Forever
			};
			_player.Play();


			// MP3 File ================================================================
			// MP3 from http://www.stephaniequinn.com/samples.htm
			//_player = new AVAudioPlayer(NSUrl.FromFilename("VivaldiSpringfromFourSeasons.mp3"), "wav", out error)
			//{
			//	Volume = 2,
			//	NumberOfLoops = -1 // Loop Forever
			//};
			//_player.Play();


		}

		public override void DidReceiveMemoryWarning()
		{
			base.DidReceiveMemoryWarning();
			// Release any cached data, images, etc that aren't in use.
		}
	}
}

About

Xamarin - [iOS] How to play an MP3 / WAV using AVAudioPlayer

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages