Beispiel #1
0
 protected override void StopSource(Entity e)
 {
     if (EntityManager.HasComponent <AudioHTMLSource>(e))
     {
         AudioHTMLSource audioNativeSource = EntityManager.GetComponentData <AudioHTMLSource>(e);
         if (audioNativeSource.sourceID > 0)
         {
             AudioHTMLNativeCalls.Stop(audioNativeSource.sourceID, true);
         }
     }
 }
Beispiel #2
0
 protected override bool IsPlaying(Entity e)
 {
     if (EntityManager.HasComponent <AudioHTMLSource>(e))
     {
         AudioHTMLSource audioHtmlSource = EntityManager.GetComponentData <AudioHTMLSource>(e);
         if (audioHtmlSource.sourceID > 0)
         {
             return(AudioHTMLNativeCalls.IsPlaying(audioHtmlSource.sourceID));
         }
     }
     return(false);
 }
Beispiel #3
0
        protected override void InitAudioSystem()
        {
            //Console.WriteLine("InitAudioSystem()");
            AudioHTMLNativeCalls.Init();
            unlocked = AudioHTMLNativeCalls.IsUnlocked();
            //Console.WriteLine("(re) checking un-locked: ");
            //Console.WriteLine(unlocked ? "true" : "false");

            TinyEnvironment env = World.TinyEnvironment();
            AudioConfig     ac  = env.GetConfigData <AudioConfig>();

            ac.initialized = true;
            ac.unlocked    = unlocked;
            env.SetConfigData(ac);
        }
Beispiel #4
0
        public LoadResult CheckLoading(IntPtr cppWrapper, EntityManager man, Entity e, ref AudioClip audioClip, ref AudioHTMLClip audioNative, ref AudioClipLoadFromFile param, ref AudioHTMLLoading loading)
        {
            LoadResult result = (LoadResult)AudioHTMLNativeCalls.CheckLoad(audioNative.clipID);

            if (result == LoadResult.success)
            {
                audioClip.status = AudioClipStatus.Loaded;
            }
            else if (result == LoadResult.failed)
            {
                audioClip.status = AudioClipStatus.LoadError;
            }

            return(result);
        }
Beispiel #5
0
        protected override void OnUpdate()
        {
            base.OnUpdate();
            TinyEnvironment env = World.TinyEnvironment();
            AudioConfig     ac  = env.GetConfigData <AudioConfig>();

            if (ac.paused != paused)
            {
                paused = ac.paused;
                if (paused)
                {
                    AudioHTMLNativeCalls.Pause();
                }
                else
                {
                    AudioHTMLNativeCalls.Resume();
                }
            }
        }
Beispiel #6
0
        public void StartLoad(
            EntityManager entityManager,
            Entity e,
            ref AudioClip audioClip,
            ref AudioHTMLClip audioHtmlClip,
            ref AudioClipLoadFromFile loader,
            ref AudioHTMLLoading loading)
        {
            if (!entityManager.HasComponent <AudioClipLoadFromFileAudioFile>(e))
            {
                audioHtmlClip.clipID = 0;
                audioClip.status     = AudioClipStatus.LoadError;
                return;
            }

            string path = entityManager.GetBufferAsString <AudioClipLoadFromFileAudioFile>(e);

            audioHtmlClip.clipID = ++IDPool.clipID;
            AudioHTMLNativeCalls.StartLoad(path, audioHtmlClip.clipID);
            audioClip.status = AudioClipStatus.Loading;
        }
Beispiel #7
0
        protected override bool PlaySource(Entity e)
        {
            var mgr = EntityManager;

            if (mgr.HasComponent <AudioSource>(e))
            {
                AudioSource audioSource = mgr.GetComponentData <AudioSource>(e);

                if (mgr.HasComponent <AudioHTMLSource>(e))
                {
                    // If there is a native source and it is IsPlaying() then
                    // can't play another, but we are done. (So return true.)
                    // Note that IsPlaying() is synchronous (which is what we want)
                    // as opposed to isPlaying which is async.
                    AudioHTMLSource ans = mgr.GetComponentData <AudioHTMLSource>(e);
                    if (AudioHTMLNativeCalls.IsPlaying(ans.sourceID))
                    {
                        return(true);
                    }
                }


                Entity clipEntity = audioSource.clip;
                if (mgr.HasComponent <AudioHTMLClip>(clipEntity))
                {
                    AudioHTMLClip clip = mgr.GetComponentData <AudioHTMLClip>(clipEntity);
                    if (clip.clipID > 0)
                    {
                        if (!unlocked)
                        {
                            AudioHTMLNativeCalls.Unlock();
                            unlocked = AudioHTMLNativeCalls.IsUnlocked();
                            if (unlocked)
                            {
                                TinyEnvironment env = World.TinyEnvironment();
                                AudioConfig     ac  = env.GetConfigData <AudioConfig>();
                                ac.unlocked = unlocked;
                                env.SetConfigData(ac);
                            }
                        }

                        if (unlocked)
                        {
                            int sourceID = ++IDPool.sourceID;
                            AudioHTMLNativeCalls.Play(clip.clipID, sourceID, audioSource.volume, audioSource.loop);
                            AudioHTMLSource audioNativeSource = new AudioHTMLSource()
                            {
                                sourceID = sourceID
                            };
                            // Need a native source as well.
                            if (mgr.HasComponent <AudioHTMLSource>(e))
                            {
                                mgr.SetComponentData(e, audioNativeSource);
                            }
                            else
                            {
                                PostUpdateCommands.AddComponent(e, audioNativeSource);
                            }

                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #8
0
 public void FreeNative(EntityManager man, Entity e, ref AudioHTMLClip audioNative)
 {
     AudioHTMLNativeCalls.Free(audioNative.clipID);
 }