Esempio n. 1
0
 public PlaybackManager()
 {
     killTimer          = new Timer(20 * 1000);
     killTimer.Elapsed += (sender, args) => StopTimers();
     NativePlayer       = new NativeAudioPlayer();
     NativePlayer.SubscribeToProperty("State", () =>
     {
         NotificationManager.Shared.ProcPlaybackStateChanged(NativePlayer.State);
         if (NativePlayer.State == PlaybackState.Playing)
         {
             StartTimers();
             killTimer.Stop();
         }
         else
         {
             killTimer.Start();
         }
     });
     NativePlayer.SubscribeToProperty("CurrentSong", () =>
     {
         var songID = NativePlayer?.CurrentSong?.Id ?? "";
         if (songID != Settings.CurrentSong)
         {
             Settings.CurrentPlaybackPercent = 0;
         }
         Settings.CurrentSong = NativePlayer?.CurrentSong?.Id ?? "";
         NotificationManager.Shared.ProcCurrentSongChanged(NativePlayer.CurrentSong);
     });
     NotificationManager.Shared.OfflineChanged += Shared_OfflineChanged;
     NotificationManager.Shared.FailedDownload += NotificationManager_Shared_FailedDownload;
 }
        public async Task ProcessFile(BackgroundDownloadFile file)
        {
            if (!(await NativeAudioPlayer.VerifyMp3(file.Destination, true)))
            {
                LogManager.Shared.Log("Failed Download", file);
                Download(file);
                return;
            }
            Files.Remove(file.TrackId);
            if (TasksDictionary.ContainsKey(file.Id))
            {
                TasksDictionary.Remove(file.Id);
            }
            var destination = Path.Combine(Locations.MusicDir, Path.GetFileName(file.Destination));

            if (File.Exists(destination))
            {
                File.Delete(destination);
            }
            File.Move(file.Destination, destination);

            LogManager.Shared.Log("File Proccessed", file);
            await OfflineManager.Shared.TrackDownloaded(file.TrackId);

            NotificationManager.Shared.ProcDownloaderStarted();
        }
    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }

        Instance = this;
        DontDestroyOnLoad(gameObject);
    }
Esempio n. 4
0
        public override void OnCreate()
        {
            base.OnCreate();
            Shared = this;
            NativeAudioPlayer.NativeInit(this);
            PlaybackManager.Shared.Init();
            Session      = new MediaSessionCompat(this, "MusicService");
            SessionToken = Session.SessionToken;
            Session.SetCallback(sessionCallback = new MediaSessionCallback());
            Session.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons |
                             MediaSessionCompat.FlagHandlesTransportControls);
            var context = ApplicationContext;
            var intent  = new Intent(ApplicationContext, typeof(NowPlayingActivity));
            var pi      = PendingIntent.GetActivity(context, 99, intent, PendingIntentFlags.UpdateCurrent);

            Session.SetSessionActivity(pi);

            sessionExtras = new Bundle();

            //		CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true);
            //        WearHelper.setSlotReservationFlags(mSessionExtras, true, true);
            //        WearHelper.setUseBackgroundFromTheme(mSessionExtras, true);

            Session.SetExtras(sessionExtras);


            try
            {
                MediaNotificationManager = new MediaNotificationManager(this);
            }
            catch (Exception ex)
            {
                LogManager.Shared.Report(ex);
                throw ex;
            }

            //VideoCastManager.getInstance().addVideoCastConsumer(mCastConsumer);
            mediaRouter = Android.Support.V7.Media.MediaRouter.GetInstance(ApplicationContext);

            //registerCarConnectionReceiver();
            Managers.NotificationManager.Shared.PlaybackStateChanged += PlaybackStateChanged;
        }