I'm developing an app with xamarin.forms which hase to play some sound. For that is created an interface 'IAudioPlayer'
namespace ClassLibrary.AudioPlayer
{
public interface IAudioPlayer
{
void PlayAudio(string filename);
}
}
And in the droid project i've got the implementation like this:
using System;
using Android.Media;
using Xamarin.Forms;
[assembly: Dependency(typeof(myApp.Droid.AudioPlayer_Android))]
namespace myApp.Droid
{
public class AudioPlayer_Android : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, ClassLibrary.AudioPlayer.IAudioPlayer, AudioTrack.IOnPlaybackPositionUpdateListener
{
public void PlayAudio(string filename)
{
var player = new MediaPlayer();
var fd = global::Android.App.Application.Context.Assets.OpenFd(filename);
player.Prepared += (s, e) =>
{
player.Start();
};
player.SetDataSource(fd.FileDescriptor, fd.StartOffset, fd.Length);
player.Prepare();
}
public void OnMarkerReached(AudioTrack track)
{
throw new NotImplementedException();
}
public void OnPeriodicNotification(AudioTrack track)
{
throw new NotImplementedException();
}
}
}
now when i call DependencyService.Get<ClassLibrary.AudioPlayer.IAudioPlayer>();
it breaks and says "Method 'Get' not found in type 'Xamarin.Forms.DependencyService'.
When im Using DependencyService.Get<>()
with another Type (Local DB implementation for example) it works fine.
Any Idea what i'm doing wrong here?