Пример #1
0
        public bool downloadStMusicFile(string musicRealAddr, string fullnameToStore, out string errStr)
        {
            bool downloadOk = false;

            errStr = "未知错误!";

            if (musicRealAddr == null ||
                musicRealAddr == "" ||
                fullnameToStore == null ||
                fullnameToStore == "")
            {
                errStr = "Songtaste歌曲真实的地址无效!";
                return(downloadOk);
            }

            Dictionary <string, string> headerDict = new Dictionary <string, string>();

            //headerDict.Add("Referer", "http://songtaste.com/music/");
            headerDict.Add("Referer", "http://songtaste.com/");

            //const int maxMusicFileLen = 100 * 1024 * 1024; // 100M
            const int maxMusicFileLen = 300 * 1024 * 1024; // 300M

            Byte[] binDataBuf = new Byte[maxMusicFileLen];

            int respDataLen = crl.getUrlRespStreamBytes(ref binDataBuf, musicRealAddr, headerDict, null, 0);

            if (respDataLen < 0)
            {
                errStr = "无法读取歌曲数据!";
                return(downloadOk);
            }

            if (crl.saveBytesToFile(fullnameToStore, ref binDataBuf, respDataLen, out errStr))
            {
                downloadOk = true;
            }

            return(downloadOk);
        }