-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Audio Can't play in Android [Sample]
update: Readme
- Loading branch information
Railway
committed
Oct 20, 2022
1 parent
2847633
commit c538fde
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
using Android.App; | ||
using Android.Content; | ||
using Android.Content.PM; | ||
using Android.OS; | ||
using MauiAudio.Platforms.Android; | ||
using MauiAudio.Platforms.Android.CurrentActivity; | ||
|
||
namespace MauiAudio.Sample; | ||
|
||
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] | ||
public class MainActivity : MauiAppCompatActivity | ||
public class MainActivity : MauiAppCompatActivity, IAudioActivity | ||
{ | ||
MediaPlayerServiceConnection mediaPlayerServiceConnection; | ||
|
||
public MediaPlayerServiceBinder Binder { get; set; } | ||
|
||
public event StatusChangedEventHandler StatusChanged; | ||
public event CoverReloadedEventHandler CoverReloaded; | ||
public event PlayingEventHandler Playing; | ||
public event BufferingEventHandler Buffering; | ||
|
||
protected override void OnCreate(Bundle savedInstanceState) | ||
{ | ||
base.OnCreate(savedInstanceState); | ||
CrossCurrentActivity.Current.Init(this, savedInstanceState); | ||
NotificationHelper.CreateNotificationChannel(ApplicationContext); | ||
if (mediaPlayerServiceConnection == null) | ||
InitializeMedia(); | ||
} | ||
|
||
private void InitializeMedia() | ||
{ | ||
mediaPlayerServiceConnection = new MediaPlayerServiceConnection(this); | ||
var mediaPlayerServiceIntent = new Intent(ApplicationContext, typeof(MediaPlayerService)); | ||
BindService(mediaPlayerServiceIntent, mediaPlayerServiceConnection, Bind.AutoCreate); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters