Пример #1
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            Xamarin.Forms.Forms.Init();

            //TODO: Replace with Xamarin.Essentials API.
            string dataDir = NSSearchPath.GetDirectories(NSSearchPathDirectory.ApplicationSupportDirectory, NSSearchPathDomain.User)[0];

            dataDir = System.IO.Path.Combine(dataDir, "Unjammit");
            // Create dataDir, if it doesnt' exist.
            if (!System.IO.Directory.Exists(dataDir))
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            Jammit.Forms.App.AllowedFileTypes = new string[] { "com.pkware.zip-archive" };
            Jammit.Forms.App.DataDirectory    = dataDir;

#if false
            Jammit.Forms.App.PlayerFactory =
                async(media) => await System.Threading.Tasks.Task.Run(() => new Audio.AppleJcfPlayer(media));
#else
            Jammit.Forms.App.PlayerFactory = async(media) => await System.Threading.Tasks.Task.Run(() =>
            {
                var player = new Audio.NAudioJcfPlayer(
                    media,
                    new Audio.AVAudioWavePlayer()
                {
                    DesiredLatency = 60, NumberOfBuffers = 2
                },
                    System.IO.Path.Combine(dataDir, "Tracks"),
                    Forms.Resources.Assets.Stick);

                player.TimerAction = () =>
                {
                    Xamarin.Forms.Device.StartTimer(new System.TimeSpan(0, 0, 1), () =>
                    {
                        Xamarin.Forms.Device.BeginInvokeOnMainThread(() => player.NotifyPositionChanged());

                        return(player.State == Audio.PlaybackStatus.Playing);
                    });
                };

                return(player);
            });
#endif

            Jammit.Forms.App.MediaLoader = new Model.FileSystemJcfLoader(dataDir);

            LoadApplication(new Jammit.Forms.App());

            base.DidFinishLaunching(notification);
            _window.Toolbar.Visible = false;
        }
Пример #2
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            // Audio options
            NSError error = AVFoundation.AVAudioSession.SharedInstance().SetCategory(AVFoundation.AVAudioSessionCategory.Playback);

            Jammit.Forms.App.AllowedFileTypes = new string[] { "com.pkware.zip-archive" };
            Jammit.Forms.App.DataDirectory    = Xamarin.Essentials.FileSystem.AppDataDirectory;

#if false
            Jammit.Forms.App.PlayerFactory =
                async(media) => await System.Threading.Tasks.Task.Run(() => new Audio.AppleJcfPlayer(media));
#else
            Jammit.Forms.App.PlayerFactory = async(media) => await System.Threading.Tasks.Task.Run(() =>
            {
                var player = new Audio.NAudioJcfPlayer(
                    media,
                    new Audio.AVAudioWavePlayer()
                {
                    DesiredLatency = 60, NumberOfBuffers = 2
                },
                    System.IO.Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "Tracks"),
                    Forms.Resources.Assets.Stick);

                player.TimerAction = () =>
                {
                    Xamarin.Forms.Device.StartTimer(new System.TimeSpan(0, 0, 1), () =>
                    {
                        Xamarin.Forms.Device.BeginInvokeOnMainThread(() => player.NotifyPositionChanged());

                        return(player.State == Audio.PlaybackStatus.Playing);
                    });
                };

                return(player);
            });
#endif

            Jammit.Forms.App.MediaLoader = new Model.FileSystemJcfLoader(Xamarin.Essentials.FileSystem.AppDataDirectory);

            LoadApplication(new Jammit.Forms.App());

            return(base.FinishedLaunching(app, options));
        }
Пример #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            // Keep screen on
            Window.AddFlags(
                WindowManagerFlags.KeepScreenOn |
                WindowManagerFlags.DismissKeyguard |
                WindowManagerFlags.ShowWhenLocked |
                WindowManagerFlags.TurnScreenOn
                );

            // Initialize LibVLCSharp
            global::LibVLCSharp.Shared.Core.Initialize();

            var config = new MediaConfiguration();

            config.EnableHardwareDecoding = true;

            Jammit.Forms.App.DataDirectory = Xamarin.Essentials.FileSystem.AppDataDirectory;

#if false
            // To prevent audo desync, use SoXR resampler.
            // See https://code.videolan.org/videolan/LibVLCSharp/issues/263#note_48330
            Jammit.Forms.App.PlayerFactory = async(media) => await System.Threading.Tasks.Task.Run(() =>
                                                                                                   new Audio.VlcJcfPlayer(media, new MediaConfiguration[] { config }, new string[] { }));
#else
            Jammit.Forms.App.PlayerFactory = async(media) => await System.Threading.Tasks.Task.Run(() =>
            {
                var player = new Audio.NAudioJcfPlayer(
                    media,
                    new Audio.AndroidWavePlayer {
                    DesiredLatency = 60, NumberOfBuffers = 2
                },
                    System.IO.Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "Tracks"),
                    Forms.Resources.Assets.Stick);

                player.TimerAction = () =>
                {
                    Xamarin.Forms.Device.StartTimer(new TimeSpan(0, 0, 1), () =>
                    {
                        Xamarin.Forms.Device.BeginInvokeOnMainThread(() => player.NotifyPositionChanged());

                        return(player.State == Audio.PlaybackStatus.Playing);
                    });
                };

                return(player);
            });
#endif

            Jammit.Forms.App.MediaLoader = new Model.FileSystemJcfLoader(Xamarin.Essentials.FileSystem.AppDataDirectory);

            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            global::Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            global::Xamarin.Forms.MessagingCenter.Subscribe <Jammit.Forms.Views.SongPage>(this, "PreventPortrait", sender =>
            {
                RequestedOrientation = ScreenOrientation.Landscape;
            });

            global::Xamarin.Forms.MessagingCenter.Subscribe <Jammit.Forms.Views.SongPage>(this, "AllowLandScapePortrait", sender =>
            {
                RequestedOrientation = ScreenOrientation.Unspecified;
            });

            LoadApplication(new Jammit.Forms.App());
        }