Example #1
0
        void Play(bool loop)
        {
            var soundComponent = ObjectForPreview as Component_Sound;

            if (soundComponent != null && soundComponent.Result != null)
            {
                long   length   = 0;
                string fileName = soundComponent.LoadFile.Value.ResourceName;
                if (!string.IsNullOrEmpty(fileName))
                {
                    try
                    {
                        length = VirtualFile.GetLength(fileName);
                        //using( var stream = VirtualFile.Open( fileName ) )
                        //	length = (int)stream.Length;
                    }
                    catch { }
                }

                if (length != 0)
                {
                    SoundModes mode = 0;
                    if (Path.GetExtension(fileName).ToLower() == ".ogg" && length > 400000)
                    {
                        mode |= SoundModes.Stream;
                    }
                    if (loop)
                    {
                        mode |= SoundModes.Loop;
                    }

                    sound = soundComponent.Result.LoadSoundByMode(mode);
                    if (sound != null)
                    {
                        channel = SoundWorld.SoundPlay(null, sound, EngineApp.DefaultSoundChannelGroup, .5f);
                    }
                }
            }
        }
Example #2
0
 public bool ChangeResourceObjectEditor(string fileName)
 {
     this.currentResourcePath     = fileName;
     this.currentResourceFileSize = 0L;
     try
     {
         if (!string.IsNullOrEmpty(this.currentResourcePath))
         {
             this.currentResourceFileSize = VirtualFile.GetLength(this.currentResourcePath);
         }
     }
     catch
     {
     }
     this.currentResourceIsArchive = false;
     try
     {
         if (!string.IsNullOrEmpty(this.currentResourcePath))
         {
             this.currentResourceIsArchive = VirtualFile.IsArchive(this.currentResourcePath);
         }
     }
     catch
     {
     }
     this.currentResourceIsInArchive = false;
     try
     {
         if (!string.IsNullOrEmpty(this.currentResourcePath))
         {
             this.currentResourceIsInArchive = VirtualFile.IsInArchive(this.currentResourcePath);
         }
     }
     catch
     {
     }
     if (this.currentResourceObjectEditor != null)
     {
         if (fileName != null && string.Compare(this.currentResourceObjectEditor.FileName, fileName, true) == 0)
         {
             return(true);
         }
         if (this.currentResourceObjectEditor.EditModeActive && !this.currentResourceObjectEditor.EndEditMode())
         {
             return(false);
         }
         this.currentResourceObjectEditor.Dispose();
         this.currentResourceObjectEditor = null;
     }
     if (fileName != null)
     {
         string text = Path.GetExtension(fileName);
         if (!string.IsNullOrEmpty(text))
         {
             text = text.Substring(1);
             if (ResourceTypeManager.Instance != null)
             {
                 ResourceType byExtension = ResourceTypeManager.Instance.GetByExtension(text);
                 if (byExtension != null)
                 {
                     Type            resourceObjectEditorType = byExtension.ResourceObjectEditorType;
                     ConstructorInfo constructor = resourceObjectEditorType.GetConstructor(new Type[0]);
                     this.currentResourceObjectEditor = (ResourceObjectEditor)constructor.Invoke(new object[0]);
                     this.currentResourceObjectEditor.Create(byExtension, fileName);
                 }
             }
         }
     }
     if (MainForm.Instance != null && this.currentResourceObjectEditor == null)
     {
         MainForm.Instance.PropertiesForm.SelectObjects(null);
     }
     return(true);
 }