コード例 #1
0
 public static IAudioData FromUrlOrFilePath(String url, bool shouldStream)
 {
     if (url.StartsWith("file://") || !url.Contains("://"))
     {
         String path = url.Replace("file://", "");
         FileModule.File file = new FileModule.File(path, FileAccess.Read);
         file.TryOpen();
         if (file.FileStream == null)
         {
             throw new MoSync.Util.ReturnValueException(MoSync.Constants.MA_AUDIO_ERR_INVALID_FILE);
         }
         return FromStream(file.FileStream);
     }
     else
     {
         return Audio.FromUrlOrFilePath(url, shouldStream);
     }
 }
コード例 #2
0
 public static IAudioData FromUrlOrFilePath(String url, bool shouldStream)
 {
     if (url.StartsWith("file://") || !url.Contains("://"))
     {
         String          path = url.Replace("file://", "");
         FileModule.File file = new FileModule.File(path, FileAccess.Read);
         file.TryOpen();
         if (file.FileStream == null)
         {
             throw new MoSync.Util.ReturnValueException(MoSync.Constants.MA_AUDIO_ERR_INVALID_FILE);
         }
         return(FromStream(file.FileStream));
     }
     else
     {
         return(Audio.FromUrlOrFilePath(url, shouldStream));
     }
 }
コード例 #3
0
        public static IAudioData FromUrlOrFilePath(String url, bool shouldStream)
        {
            if (shouldStream)
            {
                UriKind uriKind = UriKind.Absolute;

                if (url.StartsWith("file://") == true || url.Contains("://") == false)
                {
                    // gaaah need to use media element here.....
                    // Media player doesn't seem to be able to stream from isostore..
                    url = url.Replace("file://", "");
                    //url = url.Insert(0, "isostore:");
                    uriKind = UriKind.Relative;
                    return(new AudioDataMediaElement(new Uri(url, uriKind)));
                }

                Uri uri = new Uri(url, uriKind);
                return(new AudioDataMediaPlayer(uri));
            }
            else
            {
                if (url.StartsWith("file://") == true || url.Contains("://") == false)
                {
                    String          filepath = url.Replace("file://", "");
                    FileModule.File file     = new FileModule.File(filepath, FileAccess.Read);
                    file.TryOpen();
                    if (file.FileStream == null)
                    {
                        throw new MoSync.Util.ReturnValueException(MoSync.Constants.MA_AUDIO_ERR_INVALID_FILE);
                    }
                    IAudioData ret = FromStream(file.FileStream, false);
                    file.Close();
                    return(ret);
                }
                else
                {
                    // maybe create a better error code for this..
                    // we don't support anything else than loading from files directly to memory.
                    throw new MoSync.Util.ReturnValueException(MoSync.Constants.MA_AUDIO_ERR_INVALID_FILENAME);
                }
            }

            throw new MoSync.Util.ReturnValueException(MoSync.Constants.MA_AUDIO_ERR_GENERIC);
        }
コード例 #4
0
ファイル: MoSyncAudio.cs プロジェクト: N00bKefka/MoSync
        public static IAudioData FromUrlOrFilePath(String url, bool shouldStream)
        {
            if (shouldStream)
            {
                UriKind uriKind = UriKind.Absolute;

                if (url.StartsWith("file://") == true || url.Contains("://") == false)
                {
                    // gaaah need to use media element here.....
                    // Media player doesn't seem to be able to stream from isostore..
                    url = url.Replace("file://", "");
                    //url = url.Insert(0, "isostore:");
                    uriKind = UriKind.Relative;
                    return new AudioDataMediaElement(new Uri(url, uriKind));
                }

                Uri uri = new Uri(url, uriKind);
                return new AudioDataMediaPlayer(uri);
            }
            else
            {
                if (url.StartsWith("file://") == true || url.Contains("://") == false)
                {
                    String filepath = url.Replace("file://", "");
                    FileModule.File file = new FileModule.File(filepath, FileAccess.Read);
                    file.TryOpen();
                    if (file.FileStream == null)
                    {
                        throw new MoSync.Util.ReturnValueException(MoSync.Constants.MA_AUDIO_ERR_INVALID_FILE);
                    }
                    IAudioData ret = FromStream(file.FileStream, false);
                    file.Close();
                    return ret;
                }
                else
                {
                    // maybe create a better error code for this..
                    // we don't support anything else than loading from files directly to memory.
                    throw new MoSync.Util.ReturnValueException(MoSync.Constants.MA_AUDIO_ERR_INVALID_FILENAME);
                }
            }

            throw new MoSync.Util.ReturnValueException(MoSync.Constants.MA_AUDIO_ERR_GENERIC);
        }