Exemplo n.º 1
0
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="encryptedPlayerRequest">The encrypted sound parameter</param>
    /// <param name="targetPath">The path to the local sound cache directory</param>
    public AudioFileManager(string encryptedPlayerRequest, string targetPath)
    {
        _targetPath             = targetPath;
        _encryptedPlayerRequest = encryptedPlayerRequest;
        _requestInfo            = new PlayerRequestInfo(encryptedPlayerRequest);

        //
        // After all is said and done, these files should be created
        //
        LocalMp3File = Functions.CombineElementsWithDelimiter("\\", _targetPath, string.Format("id{0}.mp3", _requestInfo.SoundId));
        LocalWavFile = Functions.CombineElementsWithDelimiter("\\", _targetPath, string.Format("id{0}.wav", _requestInfo.SoundId));
    }
        public void TestConstructor()
        {
            PlayerRequestInfo requestInfo = new PlayerRequestInfo(sample2digitId);

            Assert.AreEqual(requestInfo.SoundId, 86, "Didn't decode 2 digit");

            string url = PlayerRequestInfo.SoundPlayerUrl(86, PlayerRequestInfo.SoundPlayerVersion.Version1, PlayerRequestInfo.PlayerDisplayType.AllDetails);   // /player/iAgIbHa


            PlayerRequestInfo req2 = new PlayerRequestInfo(sample3digitId);

            Assert.AreEqual(req2.SoundId, 102, "Didn't decode 3 digit");
        }
        public void Test_EncodingAndDecoding()
        {
            const int maxSoundId    = 999999999; // 999,999,999 sound ids
            const int desiredCycles = 1000;
            int       increment     = maxSoundId / desiredCycles;

            for (int loop = 1; loop <= maxSoundId; loop += increment)
            {
                PlayerRequestInfo.SoundPlayerVersion ver  = PlayerRequestInfo.SoundPlayerVersion.Version1;
                PlayerRequestInfo.PlayerDisplayType  type = PlayerRequestInfo.PlayerDisplayType.AllDetails;

                string url = PlayerRequestInfo.SoundPlayerUrl(loop, ver, type);

                int    lastSlashPos = url.LastIndexOf("/");
                string encryptedId  = url.Substring(lastSlashPos + 1);

                PlayerRequestInfo req = new PlayerRequestInfo(encryptedId);

                Assert.AreEqual(loop, req.SoundId, "Didn't decode sound id!");
                Assert.AreEqual(ver, req.Version, "Didn't decode version!");
                Assert.AreEqual(type, req.Type, "Didn't decode type");
            }
        }
Exemplo n.º 4
0
    /// <summary>
    /// The page load function
    /// </summary>
    /// <param name="sender">The sender object</param>
    /// <param name="e">The event args</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        //
        // The route stuff is set up in Global.asax
        //
        string encryptedPlayerRequest = Page.RouteData.Values["encryptedId"] as string;
        //string soundId = string.Empty;

        PlayerRequestInfo requestInfo = new PlayerRequestInfo(encryptedPlayerRequest);

        //
        // Let's validate the ID and, while we're at it, grab some sound info from the DB
        //
        if (requestInfo.IsValid)        // Functions.IsNumeric(soundId))re
        {
            theSound = DataManager.GetSoundDetails(requestInfo.SoundId);
        }
        else
        {
            //
            // Todo: put this into the event log or something?
            //
            string problem = requestInfo.InvalidReason;
        }

        if (theSound != null)
        {
            //
            // Interesting option for loading the sound data.  Put it inline with the element.
            // Pros: mobile browser doesn't have to go to the server again to get the sound data.
            // Cons: the page will seem more sluggish to load.
            //
            // SoundSrcData = string.Format("data:{0};base64,{1}", MimeTypeFromFileName(theSound.FileName), theSound.Data);

            AudioFileManager files = new AudioFileManager(encryptedPlayerRequest, HttpContext.Current.Server.MapPath(Config.CacheSoundsDirectory));
            files.CreateTempFiles();

            if (files.HaveAtLeastOneFile())
            {
                //
                // Tell the browser to load the data from this url.  Pass the encrypted sound id to keep people from being able to easily
                // go through all the sounds.
                //
                SoundSrcDataMp3            = string.Format("{0}/handlers/soundbuilder.ashx?soundid={1}&type={2}", Config.ServerName, encryptedPlayerRequest, (int)PlayerRequestInfo.AudioFileTypeCode.Mp3);
                mp3LinkPlaceholder.Visible = files.HaveFileOfType(PlayerRequestInfo.AudioFileTypeCode.Mp3);

                SoundSrcDataWav            = string.Format("{0}/handlers/soundbuilder.ashx?soundid={1}&type={2}", Config.ServerName, encryptedPlayerRequest, (int)PlayerRequestInfo.AudioFileTypeCode.Wav);
                wavLinkPlaceholder.Visible = files.HaveFileOfType(PlayerRequestInfo.AudioFileTypeCode.Wav);

                if (requestInfo.Type == PlayerRequestInfo.PlayerDisplayType.AllDetails)
                {
                    //
                    // Let's show all the sound details
                    //
                    SoundDetailsPlaceholder.Visible = true;
                    JavascriptPlaceholder.Visible   = true;

                    Title = string.Format("{0} - Otamata Soundplayer", theSound.Name);

                    if (theSound.HasIcon)
                    {
                        IconImage = string.Format("{0}/handlers/getsoundicon.ashx?soundid={1}", Config.ServerName, encryptedPlayerRequest);
                    }
                    else
                    {
                        IconImage = string.Format("{0}/images/default-icon1.png", Config.ServerName);
                    }
                }
                else if (requestInfo.Type == PlayerRequestInfo.PlayerDisplayType.NoInfoButWithOptionToShowInfo)
                {
                    //
                    // Not showing info, but the user can click a link to more info
                    //
                    ViewSoundDetailsLinkPlaceholder.Visible = true;
                    LinkToFullDetails = PlayerRequestInfo.SoundPlayerUrl(requestInfo.SoundId, requestInfo.Version, PlayerRequestInfo.PlayerDisplayType.AllDetails);
                }
                else
                {
                    //
                    // Default - no details
                    //
                }

                /*
                 *
                 * Browser        HTML5+WAV   HTML5+MP3   Embed+MP3       Embed+WAV
                 * Firefox        N           N           Y               Y
                 * IE             N           Y           N               N
                 * Safari Mac     Y           Y           Y (weird)       Y (fine)
                 * Safari iOS     N           Y           Y (new plyr)    N (err msg)
                 * Android        N           Y           N               N
                 *
                 */

                if (CanPlayHTML5Sounds)
                {
                    PlayerControlsMultiview.ActiveViewIndex = (int)PlayerControlsMultiviewEnum.HTML5Player;
                }
                else
                {
                    if (files.HaveFileOfType(PlayerRequestInfo.AudioFileTypeCode.Mp3))
                    {
                        EmbedSoundFileUrl = SoundSrcDataMp3;
                        EmbedMimeType     = "audio/mp3";
                    }
                    else if (files.HaveFileOfType(PlayerRequestInfo.AudioFileTypeCode.Wav))
                    {
                        EmbedSoundFileUrl = SoundSrcDataWav;
                        EmbedMimeType     = "audio/wav";
                    }

                    PlayerControlsMultiview.ActiveViewIndex = (int)PlayerControlsMultiviewEnum.EmbedPlayer;
                }

                PlayerMultiview.ActiveViewIndex = (int)PlayerMultiviewEnum.ValidSound;
            } // HaveAtLeastOnefile
            else
            {
                PlayerMultiview.ActiveViewIndex = (int)PlayerMultiviewEnum.InvalidSound;
            }
        }
        else
        {
            PlayerMultiview.ActiveViewIndex = (int)PlayerMultiviewEnum.InvalidSound;
        }


        AboutOtamataLink = Functions.CombineUrlElements(Config.ServerName, string.Empty);
    }
Exemplo n.º 5
0
    /// <summary>
    /// The page load function
    /// </summary>
    /// <param name="sender">The sender object</param>
    /// <param name="e">The event args</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        //
        // The route stuff is set up in Global.asax
        //
        string encryptedPlayerRequest = Page.RouteData.Values["encryptedId"] as string;
        //string soundId = string.Empty;

        PlayerRequestInfo requestInfo = new PlayerRequestInfo(encryptedPlayerRequest);

        //
        // Let's validate the ID and, while we're at it, grab some sound info from the DB
        //
        if (requestInfo.IsValid)        // Functions.IsNumeric(soundId))re
        {
            theSound = DataManager.GetSoundDetails(requestInfo.SoundId);
        }
        else
        {
            //
            // Todo: put this into the event log or something?
            //
            string problem = requestInfo.InvalidReason;
        }

        if (theSound != null)
        {
            //
            // Interesting option for loading the sound data.  Put it inline with the element.
            // Pros: mobile browser doesn't have to go to the server again to get the sound data.
            // Cons: the page will seem more sluggish to load.
            //
            // SoundSrcData = string.Format("data:{0};base64,{1}", MimeTypeFromFileName(theSound.FileName), theSound.Data);

            //
            // Tell the browser to load the data from this url.  Pass the encrypted sound id to keep people from being able to easily
            // go through all the sounds.
            //
            SoundSrcData = string.Format("{0}/handlers/getsound.ashx?soundid={1}", Config.ServerName, encryptedPlayerRequest);

            PlayerMultiview.ActiveViewIndex = 0;

            if (requestInfo.Type == PlayerRequestInfo.PlayerDisplayType.AllDetails)
            {
                //
                // Let's show all the sound details
                //
                SoundDetailsPlaceholder.Visible = true;
                JavascriptPlaceholder.Visible   = true;

                Title = string.Format("{0} - Otamata Soundplayer", theSound.Name);

                if (theSound.HasIcon)
                {
                    IconImage = string.Format("{0}/handlers/getsoundicon.ashx?soundid={1}", Config.ServerName, encryptedPlayerRequest);
                }
                else
                {
                    IconImage = string.Format("{0}/images/default-icon1.png", Config.ServerName);
                }
            }
            else if (requestInfo.Type == PlayerRequestInfo.PlayerDisplayType.NoInfoButWithOptionToShowInfo)
            {
                //
                // Not showing info, but the user can click a link to more info
                //
                ViewSoundDetailsLinkPlaceholder.Visible = true;
                LinkToFullDetails = PlayerRequestInfo.SoundPlayerUrl(requestInfo.SoundId, requestInfo.Version, PlayerRequestInfo.PlayerDisplayType.AllDetails);
            }
            else
            {
                //
                // Default - no details
                //
            }

            if (CanPlaySounds)
            {
                //UserInstructions.ActiveViewIndex = 0;
                PlayerControlsMultiview.ActiveViewIndex = 0;
            }
            else
            {
                // UserInstructions.ActiveViewIndex = 1;
                PlayerControlsMultiview.ActiveViewIndex = 1;
            }
        }
        else
        {
            PlayerMultiview.ActiveViewIndex = 1;
        }


        AboutOtamataLink = Functions.CombineUrlElements(Config.ServerName, "aboutus.aspx");
    }