Skip to content

Commit

Permalink
#8 Add the way to use without init
Browse files Browse the repository at this point in the history
  • Loading branch information
Railway committed Jul 14, 2023
1 parent fe1cecf commit 269704b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions MauiAudio.Sample/Services/PlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public partial class PlayerService:ObservableObject
public event EventHandler NewEpisodeAdded;
public event EventHandler IsPlayingChanged;

public PlayerService(INativeAudioService audioService)
public PlayerService()
{
this.audioService = audioService;
this.audioService = NativeAudioService.Current;
PlayList = new List<MediaPlay>();
audioService.PlayNext += AudioService_PlayNext;
audioService.PlayPrevious += AudioService_PlayPrevious;
Expand Down
1 change: 1 addition & 0 deletions MauiAudio/INativeAudioService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public interface INativeAudioService
{
public static INativeAudioService Current;
Task InitializeAsync(string audioURI);
Task InitializeAsync(MediaPlay media);
Task PlayAsync(double position = 0);
Expand Down
2 changes: 1 addition & 1 deletion MauiAudio/MauiAudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</TargetPlatformMinVersion>
<Version>1.2.1</Version>
<Version>1.2.2</Version>
<RootNamespace>$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<PackageId>Plugin.MauiAudio</PackageId>
Expand Down
2 changes: 2 additions & 0 deletions MauiAudio/NativeAudioService.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace MauiAudio;

public class NativeAudioService : INativeAudioService
{
static NativeAudioService current;
public static INativeAudioService Current => current ??= new NativeAudioService();
IAudioActivity instance;
double volume = 1;
double balance = 0;
Expand Down
2 changes: 2 additions & 0 deletions MauiAudio/NativeAudioService.macios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace MauiAudio;

public class NativeAudioService : INativeAudioService
{
static NativeAudioService current;
public static INativeAudioService Current => current ??= new NativeAudioService();
//AVPlayer avPlayer;
AVAudioPlayer avPlayer;
float volume = 1;
Expand Down
2 changes: 2 additions & 0 deletions MauiAudio/NativeAudioService.windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace MauiAudio;

public class NativeAudioService : INativeAudioService
{
static NativeAudioService current;
public static INativeAudioService Current => current ??= new NativeAudioService();
MediaPlayer mediaPlayer;

public bool IsPlaying => mediaPlayer != null
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ Add the [NuGet package](https://www.nuget.org/packages/Plugin.MauiAudio/) to the
- Select Plugin.MauiAudio

## Init

In CreateMauiApp()[MauiProgram.cs]
#### Version ≥ 1.2.2
No Need init!
Directly using it!
```c#
var audioService = NativeAudioService.Current;
```

#### Version ≥ 1.0.3:
In CreateMauiApp()[MauiProgram.cs]

```c#
using MauiAudio;
Expand All @@ -30,6 +35,7 @@ builder.UseMauiAudio()
```

#### Version < 1.0.3:
In CreateMauiApp()[MauiProgram.cs]

```c#
#if WINDOWS
Expand Down Expand Up @@ -123,6 +129,15 @@ await audioService.PauseAsync();
```

## Interface
### Version ≥ 1.2.2

```c#
public interface INativeAudioService
{
public static INativeAudioService Current;
······
}
```

### Version ≥ 1.0.6

Expand Down

0 comments on commit 269704b

Please sign in to comment.