i am new to Xamarin.i am trying to play sound using AVPlayerViewController in Xamrin.iOS from list view.Here is my button Action.
var playBtn = new Button () {
WidthRequest = 50,
HeightRequest = 50,
BackgroundColor = Color.Transparent,
Command = new Command(() =>{
DependencyService.Get().PlayAudioFile("Audio.mp3");
})
playBtn is custom cell button.Cell data is Populated using XAML The "PlayAudioFile" is an interface and is Platform specific.i am currently using it for iOS. Here is my iOS UIViewController Code
public void PlayAudioFile(string fileName)
{
string sFilePath = NSBundle.MainBundle.PathForResource(Path.GetFileNameWithoutExtension(fileName), Path.GetExtension(fileName));
var url = NSUrl.FromString (sFilePath);
var player = new AVPlayer (url);
player.Rate = 0.25f;
var playerVC = new AVPlayerViewController();
playerVC.Player = player;
playerVC.AllowsPictureInPicturePlayback = true;
playerVC.View.Frame = this.View.Frame;
player.Play ();
this.PresentViewController (playerVC, true, null);
}
But the AVPlayerViewController is not playing audio and nor its Presenting in view controller.What am i doing wrong. Thanks in Advance.