A light-weight and easy to use cross-platform audio player
for Windows UWP, Xamarin.iOS, Xamarin.Android, Xamarin.Mac, Xamarin.tvOS and
Xamarin.Forms. Load wav and mp3 files from any location including a shared
library. Works well for sound effects or music. Multiple instances can be
instantiated to play multiple sources simultaniously.
Install-Package Xam.Plugin.SimpleAudioPlayer -Version 1.1.0
Dependencies
· .NETPlatform 5.0
- No dependencies.
· .NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
· MonoAndroid 1.0
- No dependencies.
· Tizen 0.0
- No dependencies.
· UAP 0.0
- No dependencies.
· Xamarin.iOS 1.0
- No dependencies.
· Xamarin.Mac 2.0
- No dependencies.
· Xamarin.TVOS 0.0
- No dependencies.
Full Details: https://github.com/adrianstevens/Xamarin-Plugins
API Usage
Call CrossSimpleAudioPlayer.Current from any project or PCL to gain access to APIsProperties
Duration: length of audio in secondsCurrentPosition: current playpack position in seconds
Volume: volume of audio between 0 and 1
Balance: balance between left and right as as double, -1 is left only, 0 is both, +1 is right only
IsPlaying: is the audio currently playing
CanSeek: can the playback position be updated
Methods
Load(Stream audioStream): load a compatible (wav, mp3, etc) audio from a streamLoad(string fileName): load a compatible audio file stored in the executing platform project
Play(): play the currently loaded audio
Stop(): stop playback and reset current position to start (0)
Pause(): pause playback (use Play() to resume)
Seek(double position): seek to a specific location in the audio (in seconds)
Please keep your mp3 files in both the platforms as below
image
Design Page Xaml
<?xml
version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SAPlayerSample.PCLAudioPage"
Title="Shared
Audio">
<StackLayout Orientation="Vertical" Spacing="5" Margin="10">
<Label Text="Postion:"
/>
<Slider x:Name="sliderPosition" />
<Label x:Name="lblPosition" />
<Button x:Name="btnPlay" Text="Play" BorderColor="Green" />
<Button x:Name="btnPause" Text="Pause" BorderColor="Blue" />
<Button x:Name="btnStop" Text="Stop" BorderColor="Red" />
<Label Text="Volume:"
/>
<Slider x:Name="sliderVolume" Minimum="0" Maximum="1"/>
</StackLayout>
</ContentPage>
Code Behind:
using Plugin.SimpleAudioPlayer.Abstractions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Xamarin.Forms;
namespace SAPlayerSample
{
public partial class PCLAudioPage : ContentPage
{
ISimpleAudioPlayer
player;
public PCLAudioPage()
{
InitializeComponent();
var stream = GetStreamFromFile("Diminished.mp3");
player
= Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.CreateSimpleAudioPlayer();
player.Load(stream);
InitControls();
}
void InitControls ()
{
sliderVolume.Value = player.Volume;
btnPlay.Clicked += BtnPlayClicked;
btnPause.Clicked +=
BtnPauseClicked;
btnStop.Clicked += BtnStopClicked;
sliderVolume.ValueChanged +=
SliderVolumeValueChanged;
sliderPosition.ValueChanged +=
SliderPostionValueChanged;
}
private void
SliderPostionValueChanged(object sender,
ValueChangedEventArgs e)
{
if (sliderPosition.Value != player.Duration)
player.Seek(sliderPosition.Value);
}
private void
SliderVolumeValueChanged(object sender,
ValueChangedEventArgs e)
{
player.Volume = sliderVolume.Value;
}
private void
BtnStopClicked(object sender,
EventArgs e)
{
player.Stop();
}
private void
BtnPauseClicked(object sender,
EventArgs e)
{
player.Pause();
}
private void
BtnPlayClicked(object sender,
EventArgs e)
{
player.Play();
sliderPosition.Maximum =
player.Duration;
sliderPosition.IsEnabled =
player.CanSeek;
Device.StartTimer(TimeSpan.FromSeconds(0.5), UpdatePosition);
}
bool UpdatePosition ()
{
lblPosition.Text = $"Postion: {(int)player.CurrentPosition} / {(int)player.Duration}";
sliderPosition.ValueChanged -=
SliderPostionValueChanged;
sliderPosition.Value =
player.CurrentPosition;
sliderPosition.ValueChanged +=
SliderPostionValueChanged;
return player.IsPlaying;
}
Stream GetStreamFromFile(string filename)
{
var assembly = typeof(App).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream("SAPlayerSample." + filename);
return stream;
}
}
}
Get Full Source Code :
System.NullReferenceException
ReplyDeleteMessage=Object reference not set to an instance of an object.
I get the same exception
ReplyDeleteAlways, ALWAYS: make sure you change the properties of whatever file you've added to your project to Embedded Resource before compiling. So your "player" value doesn't throw that exception.
DeleteHow you will play list of sounds?
ReplyDeleteI tried to get list of sounds and play in foreach or for loop, but it will iterate all and play the last one.
I used thread sleeping (duration of trak) to wait and play each track, but it will stop the system and no option to pause or resume it till end of duration.
Any sulotion please!
Hey! I simply wish to give an enormous thumbs up for the good information you’ve got here on this post. I will likely be coming back to your blog for more soon. Mega888 game client download
ReplyDeleteI’m curious to find out what blog system you have been using? I’m experiencing some small security problems with my latest website and I would like to find something more risk-free. Do you have any suggestions? wettanbieter ohne oasis
ReplyDeletewhatsapp gΓΆrΓΌntΓΌlΓΌ show
ReplyDeleteΓΌcretli.show
XH3
https://istanbulolala.biz/
ReplyDelete5K0A5
tekirdaΔ evden eve nakliyat
ReplyDeletekocaeli evden eve nakliyat
yozgat evden eve nakliyat
osmaniye evden eve nakliyat
amasya evden eve nakliyat
TLR5
dΓΌzce evden eve nakliyat
ReplyDeletedenizli evden eve nakliyat
kΔ±rΕehir evden eve nakliyat
Γ§orum evden eve nakliyat
afyon evden eve nakliyat
EUJN
AD0CC
ReplyDeleteYalova Lojistik
Mamak Boya UstasΔ±
Δ°stanbul Evden Eve Nakliyat
MuΕ Lojistik
AΔrΔ± Εehirler ArasΔ± Nakliyat
Rize ParΓ§a EΕya TaΕΔ±ma
Chat Gpt Coin Hangi Borsada
ΓerkezkΓΆy Korkuluk
Shibanomi Coin Hangi Borsada
4FBC6
ReplyDeleteDΓΌzce Lojistik
BalΔ±kesir Lojistik
Aksaray Εehir Δ°Γ§i Nakliyat
Osmaniye Evden Eve Nakliyat
TekirdaΔ Εehirler ArasΔ± Nakliyat
Γnye KurtarΔ±cΔ±
Amasya ParΓ§a EΕya TaΕΔ±ma
Konya ParΓ§a EΕya TaΕΔ±ma
Coinex GΓΌvenilir mi
CF459
ReplyDeleteSivas Evden Eve Nakliyat
Burdur Lojistik
Milyon Coin Hangi Borsada
Pancakeswap GΓΌvenilir mi
Artvin Lojistik
Artvin Evden Eve Nakliyat
ΓerkezkΓΆy Korkuluk
AdΔ±yaman Εehirler ArasΔ± Nakliyat
TekirdaΔ Cam Balkon
Hi, I'm manager of Ganja Skunks, Feel Free Contact Us about medicines and pharma:
ReplyDeletecan of coke
Hi, I'm manager of Ganja Skunks, Feel Free Contact Us about medicines and pharma:
ReplyDeleteAlaskan Thunderfuck Weed Strain
Due to the use of Chebe Powder, it is common in Chad for the hair to grow past the waist of women in Chad. Chebe moisturizes hair and prevents breakage.
ReplyDeleteafrican hair grease
8DBE1
ReplyDeleteΓankaya Boya UstasΔ±
ΓerkezkΓΆy Γekici
Giresun Evden Eve Nakliyat
Isparta Evden Eve Nakliyat
Mercatox GΓΌvenilir mi
Tunceli Evden Eve Nakliyat
Probit GΓΌvenilir mi
Yenimahalle Fayans UstasΔ±
Antalya Evden Eve Nakliyat
Renting a single 15 passenger van is often more cost-effective than renting multiple smaller vehicles to accommodate the same number of passengers.
ReplyDelete15 passenger van rental atlanta
1AEF6
ReplyDeleteBinance NasΔ±l KayΔ±t Olunur
Binance NasΔ±l OynanΔ±r
Bitcoin NasΔ±l OynanΔ±r
Binance Neden Tercih Edilir
Kripto Para NasΔ±l ΓΔ±karΔ±lΔ±r
Coin Kazma
Kripto Para Kazanma
resimli magnet
Binance NasΔ±l OynanΔ±r
EEEEA
ReplyDeleteRESΔ°MLΔ° MAGNET
0A1E7
ReplyDeleteresimli Magnet
C1B89
ReplyDeleteResimli Magnet
1BA47
ReplyDeleteokex
https://kapinagelsin.com.tr/
bitexen
papatya sabunu
gate io
lavanta sabunu
Δ±sΔ±rgan sabunu
gate io
kaldıraç ne demek
5F80E
ReplyDeletebingx
kripto para kanallarΔ± telegram
canlΔ± sohbet ucretsiz
binance
poloniex
huobi
bitexen
kΔ±zlarla canlΔ± sohbet
kucoin
ED498
ReplyDeletebitcoin seans saatleri
kripto telegram gruplarΔ±
huobi
okex
probit
copy trade nedir
kripto para haram mΔ±
bkex
okex
04E34
ReplyDelete----
----
----
----
----
----
----
----
matadorbet
fgbhxfdbgvdxrf
ReplyDeleteΨ΅ΩΨ§ΩΨ© Ψ§ΩΨ±Ψ§Ω Ψ¨Ω ΩΩ
I am usually to blogging and i also actually appreciate your site content. The content has really peaks my interest. My goal is to bookmark your website and keep checking choosing details. babysitting jobs cardiff
ReplyDeleteΨ΄Ψ±ΩΨ© Ω ΩΨ§ΩΨΨ© Ψ§ΩΩΨ¦Ψ±Ψ§Ω Ψ¨Ψ§ΩΨ§ΨΨ³Ψ§Ψ‘ TMig1tMJ19
ReplyDeleteYou have observed very interesting details ! ps decent internet site . mexican food
ReplyDeleteThank you for another wonderful post. Where else could anyone get that type of information in such a perfect way of writing? I have a presentation next week, and I’m on the look for such information. Unfallwagen Verkaufen
ReplyDelete