コード例 #1
0
 private void LoadTagsDB()
 {
     try
     {
         Ares.Tags.ITagsDBFiles tagsDBFiles = Ares.Tags.TagsModule.GetTagsDB().FilesInterface;
         String filePath = System.IO.Path.Combine(Ares.Settings.Settings.Instance.MusicDirectory, tagsDBFiles.DefaultFileName);
         // if reading from a smb share, copy the database to a local file since SQLite can't open databases from input streams or memory bytes
         if (filePath.IsSmbFile())
         {
             String cacheFileName = System.IO.Path.GetTempFileName();
             try
             {
                 using (var ifs = new System.IO.BufferedStream(SambaHelpers.GetSambaInputStream(filePath)))
                     using (var ofs = System.IO.File.Create(cacheFileName))
                     {
                         ifs.CopyTo(ofs);
                     }
             }
             catch (System.IO.IOException ioEx)
             {
                 LogException(ioEx);
                 ShowToast(String.Format(Resources.GetString(Resource.String.tags_db_error), ioEx.Message));
                 return;
             }
             filePath = cacheFileName;
         }
         tagsDBFiles.OpenOrCreateDatabase(filePath);
     }
     catch (Ares.Tags.TagsDbException ex)
     {
         LogException(ex);
         ShowToast(String.Format(Resources.GetString(Resource.String.tags_db_error), ex.Message));
     }
 }
コード例 #2
0
 public static String GetDirectory(String filePath)
 {
                 #if ANDROID
     if (filePath.IsSmbFile())
     {
         return(SambaHelpers.GetDirectoryName(filePath));
     }
                 #endif
     return(System.IO.Path.GetDirectoryName(filePath));
 }
コード例 #3
0
 public static bool FileExists(String filePath)
 {
                 #if ANDROID
     if (filePath.IsSmbFile())
     {
         return(SambaHelpers.FileExists(filePath));
     }
                 #endif
     return(System.IO.File.Exists(filePath));
 }
コード例 #4
0
 public static System.IO.Stream CreateFileOutputStream(String filePath)
 {
                 #if ANDROID
     if (filePath.IsSmbFile())
     {
         return(SambaHelpers.GetSambaOutputStream(filePath));
     }
                 #endif
     return(System.IO.File.Create(filePath));
 }
コード例 #5
0
 public static void CreateDirectory(String dirPath)
 {
                 #if ANDROID
     if (dirPath.IsSmbFile())
     {
         SambaHelpers.CreateDirectory(dirPath);
         return;
     }
                 #endif
     System.IO.Directory.CreateDirectory(dirPath);
 }
コード例 #6
0
 public static String AppendFileName(String dir, String name)
 {
                 #if ANDROID
     if (dir.IsSmbFile())
     {
         return(SambaHelpers.AppendFileName(dir, name));
     }
                 #endif
     name = name.Replace('/', System.IO.Path.DirectorySeparatorChar);
     return(System.IO.Path.Combine(dir, name));
 }
コード例 #7
0
 public static System.IO.Stream GetFileContentStream(String filePath)
 {
                 #if ANDROID
     if (filePath.IsSmbFile())
     {
         /*
          * using (var stream = SambaHelpers.GetSambaInputStream(filePath))
          * {
          *      var bytes = new byte[stream.Length];
          *      stream.Read(bytes, 0, bytes.Length);
          *      return new System.IO.MemoryStream(bytes);
          * }
          */
         return(SambaHelpers.GetSambaInputStream(filePath));
     }
                 #endif
     return(new System.IO.FileStream(filePath, System.IO.FileMode.Open));
 }
コード例 #8
0
        public int PlayFile(ISoundFile file, int fadeInTime, PlayingFinished callback, bool loop)
        {
            int      channel     = 0;
            BASSFlag speakerFlag = GetSpeakerFlag(file);
            BASSFlag decodeFlag  = BASSFlag.BASS_STREAM_DECODE;

            if (file.SoundFileType == SoundFileType.Music && file.Effects.SpeakerAssignment.Active)
            {
                switch (file.Effects.SpeakerAssignment.Assignment)
                {
                case Data.SpeakerAssignment.AllSpeakers:
                case Data.SpeakerAssignment.BothCenterRears:
                case Data.SpeakerAssignment.BothFronts:
                case Data.SpeakerAssignment.BothRears:
                case Data.SpeakerAssignment.CenterAndSubwoofer:
                case Data.SpeakerAssignment.Default:
                    break;

                default:
                    decodeFlag |= BASSFlag.BASS_SAMPLE_MONO;
                    break;
                }
            }
#if MONO
            System.Runtime.InteropServices.GCHandle gcHandle = new System.Runtime.InteropServices.GCHandle();
#endif
            if (file.SoundFileType == SoundFileType.WebRadio)
            {
                channel = Bass.BASS_StreamCreateURL(file.Path, 0, decodeFlag | BASSFlag.BASS_STREAM_BLOCK, null, IntPtr.Zero);
            }
            else
            {
#if MONO
                byte[] buffer = null;
                long   length = 0;
                try
                {
#if ANDROID
                    if (file.Path.IsSmbFile())
                    {
                        buffer = SambaHelpers.GetFileContent(file.Path);
                        length = buffer.Length;
                    }
                    else
                    {
#endif
                    System.IO.FileStream fs = System.IO.File.OpenRead(file.Path);
                    length = fs.Length;
                    buffer = new byte[length];
                    fs.Read(buffer, 0, (int)length);
                    fs.Close();
#if ANDROID
                }
#endif
                }
                catch (System.IO.IOException e)
                {
                    ErrorHandling.ErrorOccurred(file.Id, e.Message);
                    return(0);
                }
                gcHandle = System.Runtime.InteropServices.GCHandle.Alloc(buffer, System.Runtime.InteropServices.GCHandleType.Pinned);
                channel  = Bass.BASS_StreamCreateFile(gcHandle.AddrOfPinnedObject(), 0L, length, decodeFlag);
#else // #if MONO
                channel = Bass.BASS_StreamCreateFile(file.Path, 0, 0, decodeFlag);
#endif
            }
            if (channel == 0)
            {
#if MONO
                if (gcHandle.IsAllocated)
                {
                    gcHandle.Free();
                }
#endif
                ErrorHandling.BassErrorOccurred(file.Id, StringResources.FilePlayingError);
                return(0);
            }
            RunningFileInfo info         = new RunningFileInfo();
            bool isStreaming             = BassStreamer.Instance.IsStreaming;
            bool useMultiSpeakerChannels = false;
            int speakers    = 2;
            int origChannel = channel;
            if (!isStreaming && file.Effects != null &&
                file.Effects.SpeakerAssignment.Active && file.Effects.SpeakerAssignment.Assignment == Data.SpeakerAssignment.AllSpeakers &&
                !file.Effects.Balance.Active && !file.Effects.Pitch.Active && !file.Effects.Tempo.Active)
            {
                speakers = Bass.BASS_GetInfo().speakers;
                if (speakers > 2)
                {
                    useMultiSpeakerChannels = true;
                }
            }

            Un4seen.Bass.BASSFlag flags = BASSFlag.BASS_DEFAULT;
            if (isStreaming)
            {
                flags = BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_STREAM_DECODE;
            }
            else if (useMultiSpeakerChannels)
            {
                flags = BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_STREAM_DECODE;
            }
            else
            {
                flags = BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_FX_FREESOURCE | speakerFlag;
            }
            channel = Un4seen.Bass.AddOn.Fx.BassFx.BASS_FX_TempoCreate(channel, flags);
            if (channel == 0)
            {
#if MONO
                if (gcHandle.IsAllocated)
                {
                    gcHandle.Free();
                }
#endif
                ErrorHandling.BassErrorOccurred(file.Id, StringResources.FilePlayingError);
                return(0);
            }
            bool result = true;
            if (useMultiSpeakerChannels)
            {
                int splitStream = Un4seen.Bass.AddOn.Mix.BassMix.BASS_Split_StreamCreate(channel, BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_SPEAKER_FRONT, null);
                if (splitStream == 0)
                {
                    result = false;
                }
                else
                {
                    int splitStream2 = Un4seen.Bass.AddOn.Mix.BassMix.BASS_Split_StreamCreate(channel, BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_SPEAKER_REAR, null);
                    if (splitStream2 == 0)
                    {
                        result = false;
                    }
                    else
                    {
                        Bass.BASS_ChannelSetLink(splitStream, splitStream2);
                        info.LinkedChannels = new List <int>();
                        info.LinkedChannels.Add(splitStream2);
                    }
                    if (result && speakers > 4)
                    {
                        int splitStream3 = Un4seen.Bass.AddOn.Mix.BassMix.BASS_Split_StreamCreate(channel, BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_SPEAKER_CENLFE, null);
                        if (splitStream3 == 0)
                        {
                            result = false;
                        }
                        else
                        {
                            Bass.BASS_ChannelSetLink(splitStream, splitStream3);
                            info.LinkedChannels.Add(splitStream3);
                        }
                    }
                    if (result && speakers > 6)
                    {
                        int splitStream4 = Un4seen.Bass.AddOn.Mix.BassMix.BASS_Split_StreamCreate(channel, BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_SPEAKER_REAR2, null);
                        if (splitStream4 == 0)
                        {
                            result = false;
                        }
                        else
                        {
                            Bass.BASS_ChannelSetLink(splitStream, splitStream4);
                            info.LinkedChannels.Add(splitStream4);
                        }
                    }
                    if (result)
                    {
                        channel = splitStream;
                    }
                }
            }
            if (result)
            {
                lock (m_Mutex)
                {
                    info.EndAction = new Action(() =>
                    {
                        callback(file.Id, channel);
                    });
                    info.Volume = file.Volume;
                }
                if (!loop)
                {
                    int sync = 0;
                    // If CueOut is active ...
                    if (file.Effects.CueOut.Active)
                    {
                        // Convert the CueOut position (seconds) into a byte offset
                        long cueOutPos = Bass.BASS_ChannelSeconds2Bytes(channel, file.Effects.CueOut.Position);
                        // Set the "end" sync to that position
                        sync = Bass.BASS_ChannelSetSync(channel, BASSSync.BASS_SYNC_POS, cueOutPos, m_CueOutSync, new IntPtr(file.Id));
                    }
                    else
                    {
                        long totalLength = Bass.BASS_ChannelGetLength(channel);
                        long endingTime  = Bass.BASS_ChannelSeconds2Bytes(channel, 0.1);

                        // Default: set the "end" sync to the end of the stream, minus one ms
                        sync = Bass.BASS_ChannelSetSync(channel, BASSSync.BASS_SYNC_POS, totalLength - endingTime, m_StartNextSync, IntPtr.Zero);
                    }

                    if (sync == 0)
                    {
#if MONO
                        if (gcHandle.IsAllocated)
                        {
                            gcHandle.Free();
                        }
#endif
                        ErrorHandling.BassErrorOccurred(file.Id, StringResources.FilePlayingError);
                        return(0);
                    }
                    else
                    {
                        lock (m_Mutex)
                        {
                            m_NotLoops[channel] = sync;
                        }
                    }
                }
                if (!SetStartVolume(file, fadeInTime, channel, info))
                {
                    return(0);
                }
                info.CrossFade = false;
                if (file.Effects != null && file.Effects.FadeOutTime != 0)
                {
                    long totalLength = Bass.BASS_ChannelGetLength(channel);
                    if (totalLength == -1)
                    {
                        ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetVolumeError);
                        return(0);
                    }
                    long fadeOutLength = Bass.BASS_ChannelSeconds2Bytes(channel, 0.001 * file.Effects.FadeOutTime);
                    if (fadeOutLength == -1)
                    {
                        ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetVolumeError);
                        return(0);
                    }
                    if (fadeOutLength > totalLength)
                    {
                        fadeOutLength = totalLength;
                    }
                    // If CueOut is active ...
                    if (file.Effects.CueOut.Active)
                    {
                        // Convert the CueOut position (seconds) into a byte offset
                        long cueOutPos = Bass.BASS_ChannelSeconds2Bytes(channel, file.Effects.CueOut.Position);
                        // Set the "end" sync to that position
                        if (Bass.BASS_ChannelSetSync(channel, BASSSync.BASS_SYNC_POS, cueOutPos - fadeOutLength, m_FadeOutSync, new IntPtr(file.Effects.FadeOutTime)) == 0)
                        {
                            ErrorHandling.BassErrorOccurred(file.Id, StringResources.FilePlayingError);
                            return(0);
                        }
                    }
                    else
                    {
                        if (Bass.BASS_ChannelSetSync(channel, BASSSync.BASS_SYNC_POS, totalLength - fadeOutLength, m_FadeOutSync, new IntPtr(file.Effects.FadeOutTime)) == 0)
                        {
                            ErrorHandling.BassErrorOccurred(file.Id, StringResources.FilePlayingError);
                            return(0);
                        }
                    }
                    if (loop)
                    {
                        // If CueOut is active ...
                        if (file.Effects.CueOut.Active)
                        {
                            // Convert the CueOut position (seconds) into a byte offset
                            long cueOutPos = Bass.BASS_ChannelSeconds2Bytes(channel, file.Effects.CueOut.Position);
                            // Set the "end" sync to that position
                            if (Bass.BASS_ChannelSetSync(channel, BASSSync.BASS_SYNC_POS, cueOutPos, m_LoopSync, new IntPtr(file.Id)) == 0)
                            {
                                ErrorHandling.BassErrorOccurred(file.Id, StringResources.FilePlayingError);
                                return(0);
                            }
                        }
                        else
                        {
                            if (Bass.BASS_ChannelSetSync(channel, BASSSync.BASS_SYNC_POS, totalLength, m_LoopSync, new IntPtr(file.Id)) == 0)
                            {
                                ErrorHandling.BassErrorOccurred(file.Id, StringResources.FilePlayingError);
                                return(0);
                            }
                        }
                    }
                    else
                    {
                        info.CrossFade = file.Effects.CrossFading;
                    }
                }
                if (file.Effects != null && file.Effects.Pitch.Active)
                {
                    float pitchValue = DetermineIntEffectValue(file.Effects.Pitch);
                    if (!Bass.BASS_ChannelSetAttribute(channel, BASSAttribute.BASS_ATTRIB_TEMPO_PITCH, pitchValue))
                    {
                        ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetEffectError);
                        return(0);
                    }
                }
                if (file.Effects != null && file.Effects.Tempo.Active)
                {
                    float tempoValue = DetermineIntEffectValue(file.Effects.Tempo);
                    if (!Bass.BASS_ChannelSetAttribute(channel, BASSAttribute.BASS_ATTRIB_TEMPO, tempoValue))
                    {
                        ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetEffectError);
                        return(0);
                    }
                }
                if (file.Effects != null && file.Effects.Balance.Active && !useMultiSpeakerChannels)
                {
                    SetBalanceEffect(channel, file.Id, file.Effects.Balance);
                }
                if (file.Effects != null && file.Effects.VolumeDB.Active)
                {
                    float volumeDB = DetermineIntEffectValue(file.Effects.VolumeDB);
                    float linear   = (float)Math.Pow(10d, volumeDB / 20);
                    int   volFx    = Bass.BASS_ChannelSetFX(channel, BASSFXType.BASS_FX_BFX_VOLUME, 1);
                    if (volFx == 0)
                    {
                        ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetEffectError);
                        return(0);
                    }
                    Un4seen.Bass.AddOn.Fx.BASS_BFX_VOLUME fxVol = new Un4seen.Bass.AddOn.Fx.BASS_BFX_VOLUME(linear, Un4seen.Bass.AddOn.Fx.BASSFXChan.BASS_BFX_CHANALL);
                    if (!Bass.BASS_FXSetParameters(volFx, fxVol))
                    {
                        ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetEffectError);
                        return(0);
                    }
                    if (info.LinkedChannels != null)
                    {
                        foreach (int splitStream2 in info.LinkedChannels)
                        {
                            int volFx2 = splitStream2 != 0 ? Bass.BASS_ChannelSetFX(splitStream2, BASSFXType.BASS_FX_BFX_VOLUME, 1) : 0;
                            if (splitStream2 != 0 && volFx2 == 0)
                            {
                                ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetEffectError);
                                return(0);
                            }
                            if (volFx2 != 0 && !Bass.BASS_FXSetParameters(volFx2, fxVol))
                            {
                                ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetEffectError);
                                return(0);
                            }
                        }
                    }
                }
#pragma warning disable CS0618 // Type or member is obsolete
                if (file.Effects != null && file.Effects.Reverb.Active)
                {
                    float linearLevel = (float)Math.Pow(10d, file.Effects.Reverb.Level / 20);
                    int   reverbFx    = Bass.BASS_ChannelSetFX(channel, BASSFXType.BASS_FX_BFX_REVERB, 1);
                    if (reverbFx == 0)
                    {
                        ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetEffectError);
                        return(0);
                    }
                    Un4seen.Bass.AddOn.Fx.BASS_BFX_REVERB fxReverb = new Un4seen.Bass.AddOn.Fx.BASS_BFX_REVERB(linearLevel, file.Effects.Reverb.Delay);
                    if (!Bass.BASS_FXSetParameters(reverbFx, fxReverb))
                    {
                        ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetEffectError);
                        return(0);
                    }
                    if (info.LinkedChannels != null)
                    {
                        foreach (int splitStream2 in info.LinkedChannels)
                        {
                            int reverbFx2 = splitStream2 != 0 ? Bass.BASS_ChannelSetFX(splitStream2, BASSFXType.BASS_FX_BFX_REVERB, 1) : 0;
                            if (splitStream2 != 0 && reverbFx2 == 0)
                            {
                                ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetEffectError);
                                return(0);
                            }
                            if (reverbFx2 != 0 && !Bass.BASS_FXSetParameters(reverbFx2, fxReverb))
                            {
                                ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetEffectError);
                                return(0);
                            }
                        }
                    }
                }
#pragma warning restore CS0618 // Type or member is obsolete
                if (loop)
                {
                    Bass.BASS_ChannelFlags(channel, BASSFlag.BASS_SAMPLE_LOOP, BASSFlag.BASS_SAMPLE_LOOP);
                }
                lock (m_Mutex)
                {
                    m_Loops[file.Id] = file;
                    if (file.Effects != null && file.Effects.CueOut.Active)
                    {
                        m_CueOutRepeats[channel] = loop;
                    }
                }

                if (file.Effects.CueIn.Active)
                {
                    Bass.BASS_ChannelSetPosition(channel, file.Effects.CueIn.Position);
                }

                if (isStreaming)
                {
                    result = BassStreamer.Instance.AddChannel(channel);
                }
                else
                {
                    result = Bass.BASS_ChannelPlay(channel, false);
                }
                if (!result)
                {
                    ErrorHandling.BassErrorOccurred(file.Id, StringResources.FilePlayingError);
                    Bass.BASS_StreamFree(channel);
#if MONO
                    if (gcHandle.IsAllocated)
                    {
                        gcHandle.Free();
                    }
#endif
                    return(0);
                }
                lock (m_Mutex)
                {
                    m_RunningFiles[channel] = info;
#if MONO
                    if (gcHandle.IsAllocated)
                    {
                        m_GCHandles[channel] = gcHandle;
                    }
#endif
                }
                return(channel);
            }
            else
            {
                ErrorHandling.BassErrorOccurred(file.Id, StringResources.FilePlayingError);
                return(0);
            }
        }