void CMPlayerUtility::OpenUrl(CMString sUrl, const UINT32 nMode/* = EMode_3mv*/, const char* coursewareID )
{
    
    string path = CMCourseDownload::GetInstance()->GetLocalFilePath(coursewareID);
    
    //先检查本地文件在不在
    if(path.size() !=0 && CMFile::FileExist(CMString(path.c_str())))
    {
    	OpenFile(CMString(path.c_str()), nMode);
    	return;
    }
    
	CMPath tmpPath(CMPath::DOWNLOAD_PATH);
    CMString sOrgUrl;

    INT32 pos = sUrl.ReverseFind(L"?sid=");
    if(pos < 0)
    	pos = sUrl.ReverseFind(L"&sid=");
    if(pos > 0)
    	sOrgUrl = sUrl.Left(pos);
    else
    	sOrgUrl = sUrl;
    
    
    CMString filename = tmpPath.String()+CMFile::GetTempFileName(sOrgUrl, "");
	if(CMFile::FileExist(filename))
    {
    	OpenFile(filename, nMode);
    	return;
    }
    //本地无此文件,去数据库读取
    if(m_nState == EReady)
    {
        m_bDataCompleted = FALSE;
        SAFEDELETE(m_pMediaData);
        m_bOnlyAudio = nMode != EMode_3mv;
        if(nMode == EMode_3mv || nMode == EMode_3ma)
            m_pMediaData = new CMNetDataSource;
		else if(nMode == EMode_aac)
			 m_pMediaData = new CMAACDataSource;
		else
			return;
        BOOL ret = FALSE;
        
//        sUrl = CMString("http://42.96.138.63/Upload/Files/root/CourseWareFile/201401/201401101233202695248e5b93f75f4685af/201401161429192546803cd48b08aa3daf7f_(960x640).3mv");
        printf("surl:%s \n",(const CHAR*)sUrl);
        
        if(m_pMediaData && m_pMediaData->Init(this, m_pStreamBuffer))
            ret = m_pMediaData->Open(sUrl, NET_VOD);
        if(ret)
        {
            m_pMediaData->Start();
            m_PlayerObserver.StateChange(m_UserData, EOpening, m_nState);
            m_nState = EOpening;
        }
        else
            SAFEDELETE(m_pMediaData);
    }
}
示例#2
0
void CMWebImage::FormatFilePath(const char* sUrl)
{
	m_sFilePath.Empty();
	CMString url = sUrl;
    INT32 pos = url.ReverseFind(L"/");
    if(pos < 0)
        return;
	m_sFilePath = CMPath(CMPath::TEMP_PATH).String() + CMFile::GetTempFileName(url, L"") + "@2x." + CMFile::GetFileExt(url.Mid(pos+1));
}
示例#3
0
BOOL CMWebImage::GetFromUrl(int nID, const char* sUrl)
{
	CMString url = sUrl;
	INT32 pos = 0;
	PicUrl * pPicUrl = NULL;

	if(!sUrl || strlen(sUrl) <= 0)
		goto ret;

    pos = url.ReverseFind(L"/");
    if(pos < 0)
        goto ret;

    if(GetFilePath(sUrl))
		return TRUE;//CMFile::DeleteFile(sFilePath);

	if(m_lstPicUrl)
	{
		for(int i=0; i<m_lstPicUrl->size();i++)
		{
			pPicUrl = (PicUrl *)m_lstPicUrl->at(i);
			if(strcmp(pPicUrl->url, sUrl) == 0)
				goto ret;
		}
	}
	//加入下载列表
	pPicUrl = new PicUrl;
	pPicUrl->id = nID;
    
    utf8ncpy(pPicUrl->url, sUrl, 299);

	if(!m_lstPicUrl)
		m_lstPicUrl = new CMList<PicUrl*>;
	m_lstPicUrl->push_back(pPicUrl);
	
	DownloadNext();

	return FALSE;
ret:
	if(m_pListener)
		m_pListener->OnFinish(m_UserData,TResult::EUnknownError,nID);
	return FALSE;	
}
示例#4
0
void CMWebImage::DownloadNext()
{
    if (CMGlobal::TheOne().IsOffline())
	{
		if(m_pListener)
			m_pListener->OnFinish(m_UserData, MERN_OFFLINE, 0);
        return;
	}
    
	if(!m_pDownloader)
	{
		m_pDownloader = new CMDownloader(this);
#if defined(PLAT_IOS) || defined(PLAT_AND)
		m_pDownloader->SetMaxFileSize(1024*1024);
#else
		m_pDownloader->SetMaxFileSize(512*1024);
#endif
	}

	if(m_pDownloader->GetStatus() == CMDownloader::RUNNING)
		return;

	if(m_lstPicUrl->size() > 0)
	{
		PicUrl* pPicUrl = (PicUrl*)m_lstPicUrl->at(0);
		if(pPicUrl)
		{
			FormatFilePath(pPicUrl->url);
			CMString sID;
			CMGlobal::TheOne().GetSessionID(sID);
			CMString url = pPicUrl->url;		
			INT32 pos = url.ReverseFind(L"?");
			if(pos < 0)
				url += L"?sid=";
			else
				url += L"&sid=";
			url += sID;
		
			m_pDownloader->Download(url, m_sFilePath);
		}
	}
}