Esempio n. 1
0
 public static void Application_Activated()
 {
     // Restart audio tracks
     for (int i = 0; i < AudioHandles.Count; ++i)
     {
         AudioHandle audioHandle = AudioHandles[i];
         audioHandle.resume(true);
     }
 }
Esempio n. 2
0
 static AudioHandle Get(String id)
 {
     for (int i = 0; i < AudioHandles.Count; ++i)
     {
         AudioHandle audioHandle = AudioHandles[i];
         if (audioHandle.id.Equals(id))
         {
             return(audioHandle);
         }
     }
     return(null);
 }
Esempio n. 3
0
        static void Trim()
        {
            // WP8 only supports one channel :(
            while (AudioHandles.Count > 0)
            {
                AudioHandle oldestHandle = null;
                DateTime    oldestTime   = DateTime.Now;

                for (int i = 0; i < AudioHandles.Count; ++i)
                {
                    AudioHandle audioHandle = AudioHandles[i];
                    if (audioHandle.mediaElement == null)
                    {
                        oldestHandle = audioHandle;
                        break;
                    }
                    else if (!audioHandle.playing)
                    {
                        oldestHandle = audioHandle;
                        break;
                    }
                    else if (!audioHandle.looping)
                    {
                        if (audioHandle.timeLastPlayed < oldestTime)
                        {
                            oldestHandle = audioHandle;
                            oldestTime   = audioHandle.timeLastPlayed;
                        }
                    }
                }

                if (oldestHandle != null)
                {
                    oldestHandle.stop();
                    oldestHandle.destroy();
                    AudioHandles.Remove(oldestHandle);
                }
                else
                {
                    break;
                }
            }
        }
Esempio n. 4
0
        static AudioHandle Prepare(String id, String url, String path)
        {
            Trim();

            if (AudioHandles.Count > 0)
            {
                return(null);
            }

            AudioHandle audioHandle = Get(id);

            if (audioHandle == null)
            {
                audioHandle      = new AudioHandle();
                audioHandle.id   = id;
                audioHandle.url  = url;
                audioHandle.path = path;

                audioHandle.prepare();
                AudioHandles.Add(audioHandle);
            }
            return(audioHandle);
        }
Esempio n. 5
0
        static AudioHandle Prepare(String id, String url, String path)
        {
            Trim();

            if (AudioHandles.Count > 0)
            {
                return null;
            }

            AudioHandle audioHandle = Get(id);
            if (audioHandle == null)
            {
                audioHandle = new AudioHandle();
                audioHandle.id = id;
                audioHandle.url = url;
                audioHandle.path = path;

                audioHandle.prepare();
                AudioHandles.Add(audioHandle);
            }
            return audioHandle;
        }
Esempio n. 6
0
        public static bool csWork(String action, String actionData)
        {
            if (action == "CCDeviceAudioManager::Reset")
            {
                MainPage.m_d3dInterop.csActionResult("CCDeviceAudioManager::Reseted", "");

                for (int i = 0; i < AudioHandles.Count; ++i)
                {
                    AudioHandle audioHandle = AudioHandles[i];
                    if (audioHandle.mediaElement != null)
                    {
                        audioHandle.stop();
                    }
                }

                return(true);
            }
            else if (action == "CCDeviceAudioManager::Prepare")
            {
                MainPage.m_d3dInterop.csActionResult("CCDeviceAudioManager::Prepare", "");

                String[] split = Regex.Split(actionData, ", ");
                if (split.Length == 3)
                {
                    String id   = split[0];
                    String url  = split[1];
                    String path = split[2];

                    Prepare(id, url, path);
                }

                return(true);
            }
            else if (action == "CCDeviceAudioManager::Play")
            {
                MainPage.m_d3dInterop.csActionResult("CCDeviceAudioManager::Play", "");

                String[] split = Regex.Split(actionData, ", ");
                if (split.Length == 5)
                {
                    String id      = split[0];
                    String url     = split[1];
                    String path    = split[2];
                    bool   restart = split[3].Equals("true");
                    bool   loop    = split[4].Equals("true");

                    AudioHandle audioHandle = Prepare(id, url, path);
                    if (audioHandle != null)
                    {
                        audioHandle.play(restart, loop);
                    }
                }

                return(true);
            }
            else if (action == "CCDeviceAudioManager::Stop")
            {
                MainPage.m_d3dInterop.csActionResult("CCDeviceAudioManager::Stop", "");

                AudioHandle audioHandle = Get(actionData);
                if (audioHandle != null)
                {
                    audioHandle.stop();
                }

                return(true);
            }
            else if (action == "CCDeviceAudioManager::Pause")
            {
                MainPage.m_d3dInterop.csActionResult("CCDeviceAudioManager::Pause", "");

                AudioHandle audioHandle = Get(actionData);
                if (audioHandle != null)
                {
                    audioHandle.pause();
                }

                return(true);
            }
            else if (action == "CCDeviceAudioManager::Resume")
            {
                MainPage.m_d3dInterop.csActionResult("CCDeviceAudioManager::Resume", "");

                AudioHandle audioHandle = Get(actionData);
                if (audioHandle != null)
                {
                    audioHandle.resume(false);
                }

                return(true);
            }
            else if (action == "CCDeviceAudioManager::SetTime")
            {
                MainPage.m_d3dInterop.csActionResult("CCDeviceAudioManager::SetTime", "");

                return(true);
            }
            else if (action == "CCDeviceAudioManager::SetVolume")
            {
                MainPage.m_d3dInterop.csActionResult("CCDeviceAudioManager::SetVolume", "");

                return(true);
            }

            return(false);
        }