⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playlistmgr.cpp

📁 media player 控件源码 用EVC编译可以进行对WINCE下media player控制
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        if (pPlaylist)
        {
            pszPath = (TCHAR*)pPlaylist->GetPath();
        }
        else
        {
            pszPath = TEXT("");
        }

        RegSetValueEx(hkResult,
                      TEXT("LastPlaylist"), 0,
                      REG_SZ, (BYTE*)pszPath,
                      (_tcslen(pszPath) + 1) * sizeof (TCHAR));

        if (m_pszMediaShare)
        {
            pszShare = m_pszMediaShare;
        }
        else
        {
            pszShare = TEXT("");
        }

        RegSetValueEx(hkResult,
                      TEXT("MediaShare"), 0,
                      REG_SZ, (BYTE*)pszShare,
                      (_tcslen(pszShare) + 1) * sizeof (TCHAR));

        RegCloseKey(hkResult);
    }
}

void CPlaylistMgr::LoadRegState()
{
    HKEY  hkResult = NULL;
    DWORD dwDisp;
    TCHAR * szPlaylist = new TCHAR[MAX_URL_LENGTH];
    TCHAR * szRegKey   = new TCHAR[REGKEY_SIZE];

    if (NULL != szPlaylist
        && NULL != szRegKey
        && ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE,
                                           TEXT("SOFTWARE\\Microsoft\\CEPlayer"),
                                           0, NULL, 0, 0, NULL, &hkResult, &dwDisp))
    {
        DWORD dwSize, dwKeyType;
        int iIter, iCur;

        for (iIter = iCur = 0; iCur < MAX_PLAYLIST_HISTORY; iIter++)
        {
            m_pszMRUPlaylist[iCur] = NULL;
            if (iIter >= MAX_PLAYLIST_HISTORY)
            {
            	iCur++;
            	continue;
            }

            szRegKey[0] = TEXT('\0');
            dwSize = MAX_URL_LENGTH;

            LoadString(g_hInst, ID_PLAYLIST1_REGKEY + iIter, szRegKey, REGKEY_SIZE);

            if (ERROR_SUCCESS != RegQueryValueEx(hkResult, szRegKey, 0, &dwKeyType,
                                                 (BYTE*)szPlaylist, &dwSize))
            {
                continue;
            }

            if (0 == _tcslen(szPlaylist))
                continue;

           	// make sure the file exists before adding it
	        WIN32_FIND_DATA fd;
    	    HANDLE hFind = FindFirstFile(szPlaylist, &fd);
    	    if (INVALID_HANDLE_VALUE == hFind)
    	    {
    	    	FindClose(hFind);
    	        continue;
    	    }

    	    FindClose(hFind);

            m_pszMRUPlaylist[iCur] = new TCHAR [_tcslen(szPlaylist) + 1];
            if (!m_pszMRUPlaylist[iCur])
            	continue;

            _tcscpy(m_pszMRUPlaylist[iCur], szPlaylist);
            iCur++;
        }

        if (REG_OPENED_EXISTING_KEY == dwDisp)
        {
            DWORD   dwType;
            TCHAR * pszLastPlaylist = new TCHAR[MAX_URL_LENGTH];
            TCHAR * pszShare        = new TCHAR[MAX_PATH];

            dwSize = MAX_PATH * sizeof (TCHAR);

            if (NULL != pszShare
                && ERROR_SUCCESS == RegQueryValueEx(hkResult,
                                                    TEXT("MediaShare"),
                                                    NULL, &dwType,
                                                    (BYTE*)pszShare,
                                                    &dwSize))
            {
                if (_tcslen(pszShare) > 0)
                {
                    if (m_pszMediaShare = new TCHAR [_tcslen(pszShare) + 1])
                    {
                        _tcscpy(m_pszMediaShare, pszShare);
                    }
                    else
                    {
                        m_pszMediaShare = pszShare;
                        pszShare = NULL;
                    }
                }
            }

            dwSize = MAX_URL_LENGTH * sizeof (TCHAR);

            //
            // WARNING:  SetCurrentPlaylist has the side effect of
            //           calling SaveRegState, so it must be the last
            //           regkey loaded.
            //
            if (NULL != pszLastPlaylist
                && ERROR_SUCCESS == RegQueryValueEx(hkResult,
                                                    TEXT("LastPlaylist"),
                                                    NULL, &dwType,
                                                    (BYTE*)pszLastPlaylist,
                                                    &dwSize))
            {
                if (_tcslen(pszLastPlaylist) > 0)
                {
                    // make sure the file exists before adding it
                    WIN32_FIND_DATA fd;
                    HANDLE hFind = FindFirstFile(pszLastPlaylist, &fd);
                    if (INVALID_HANDLE_VALUE == hFind)
                    {
                        SaveRegState();
                    }
                    else
                    {
                        SetCurrentPlaylist(pszLastPlaylist);
                        FindClose(hFind);
                    }
                }
            }

            delete [] pszShare;
            delete [] pszLastPlaylist;
        }

        RegCloseKey(hkResult);
    }

    delete [] szPlaylist;
    delete [] szRegKey;
}

void CPlaylistMgr::LoadLocalPlaylists()
{
    list_t * pTemp  = m_pPlaylists;
    int      iCount = 0;

    //
    // Clear out any previously loaded playlists
    //
    while (pTemp)
    {
        m_pPlaylists = pTemp->pNext;
        delete pTemp;

        if (m_pPlaylists) m_pPlaylists->pPrev = NULL;
        pTemp = m_pPlaylists;
    }

    // Search the device for playlists
    for (int i = 0; i < s_iIncludePathLength; i++)
    {
        iCount += FindPlaylists(s_pszIncludePath[i], iCount);
    }

    m_bLoadedLocalPlaylists = true;
}

int CPlaylistMgr::FindPlaylists(LPCTSTR pszPath, int iCount)
{
    WIN32_FIND_DATA ffd;
    HANDLE          hFind;
    TCHAR           szBasePath[MAX_PATH];
    TCHAR           szFindPath[MAX_PATH];
    BOOL            bFoundFile = FALSE;

    for (int i = 0; i < s_iExcludePathLength; i++)
    {
        if (0 == _tcscmp(s_pszExcludePath[i], pszPath))
        {
            return 0;
        }
    }

    if (TEXT('\\') == pszPath[0])
    {
        if (TEXT('\0') != pszPath[1])
        {
            _stprintf(szFindPath, TEXT("%s\\*"), pszPath);
        }
        else
        {
            _stprintf(szFindPath, TEXT("%s*"), pszPath);
        }

        _tcscpy(szBasePath, pszPath);
    }
    else
    {
        _stprintf(szBasePath, TEXT("\\%s"), pszPath);
        _stprintf(szFindPath, TEXT("\\%s\\*"), pszPath);
    }

    hFind = FindFirstFile(szFindPath, &ffd);

    if (INVALID_HANDLE_VALUE != hFind)
    {
        bFoundFile = TRUE;
    }

    while (bFoundFile)
    {
        if (TEXT('\0') != szBasePath[0]
            && TEXT('\\') == szBasePath[_tcslen(szBasePath) - 1])
        {
            _stprintf(szFindPath, TEXT("%s%s"), szBasePath, ffd.cFileName);
        }
        else
        {
            _stprintf(szFindPath, TEXT("%s\\%s"), szBasePath, ffd.cFileName);
        }

        if (FILE_ATTRIBUTE_DIRECTORY & ffd.dwFileAttributes)
        {
            iCount += FindPlaylists(szFindPath, iCount);
        }

        if (!(FILE_ATTRIBUTE_HIDDEN & ffd.dwFileAttributes))
        {
            int iLength = _tcslen(ffd.cFileName);

            if (iLength >= 5
                && TEXT('.') == ffd.cFileName[iLength - 4]
                && (TEXT('A') == ffd.cFileName[iLength - 3]
                    || TEXT('a') == ffd.cFileName[iLength - 3])
                && (TEXT('S') == ffd.cFileName[iLength - 2]
                    || TEXT('s') == ffd.cFileName[iLength - 2])
                && (TEXT('X') == ffd.cFileName[iLength - 1]
                    || TEXT('x') == ffd.cFileName[iLength - 1]))
            {
                if (AddPlaylist(szFindPath, iCount + 1))
                {
                    iCount++;
                }
            }
        }

        bFoundFile = FindNextFile(hFind, &ffd);
    }

    if (INVALID_HANDLE_VALUE != hFind)
    {
        FindClose(hFind);
    }

    return iCount;
}

void CPlaylistMgr::UpdateLocalContent()
{
    int     iCount = 0;
    int     i;
    HCURSOR hPrevCursor;

    // Make the cursor appear as an hour glass to let the user know something
    // is happening.
    hPrevCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));

    // Clear the old Local Content playlist
    if (m_pLocalContent)
    {
        m_pLocalContent->DeleteAll();
    }
    else if (m_pLocalContent = new CPlaylist(TEXT("Local Content")))
    {
            m_pLocalContent->IsTransient(true);
    }
    else
    {
        return;
    }

    for (i = 0; i < s_iIncludePathLength; i++)
    {
        iCount += FindMediaFiles(s_pszIncludePath[i], m_pLocalContent, iCount);
    }

    //
    // Search the optional network path (if we have the network redirector
    // installed)
    //
    if (NULL != m_pszMediaShare
        && IsAPIReady(SH_WNET))
    {
        iCount += FindMediaFiles(m_pszMediaShare, m_pLocalContent, iCount);
    }

    //
    // Add anything from "Favorites" to the bottom of the local content list
    //
    int iFavCount = 0;

    if (m_pFavorites) iFavCount = (int)m_pFavorites->GetCount();

    if (iFavCount > 0)
    {
        for (i = 0; i < iFavCount; i++)
        {
            CMediaClip * pClip = m_pFavorites->GetTrack(i);

            if (NULL != pClip
                && NULL != pClip->GetPath()
                && m_pLocalContent->InsertTrack(iCount + 1, pClip->GetPath()))
            {
                iCount++;
            }
        }
    }

    // Restore the old cursor
    SetCursor(hPrevCursor);
}

int CPlaylistMgr::FindMediaFiles(LPCTSTR pszPath, CPlaylist * pLocalContent, int iCount)
{
    WIN32_FIND_DATA ffd;
    HANDLE          hFind;
    TCHAR           szBasePath[MAX_PATH];
    TCHAR           szFindPath[MAX_PATH];
    BOOL            bFoundFile = FALSE;

    for (int i = 0; i < s_iExcludePathLength; i++)
    {
        if (0 == _tcscmp(s_pszExcludePath[i], pszPath))
        {
            return 0;
        }
    }

    if (TEXT('\\') == pszPath[0])
    {
        if (TEXT('\0') != pszPath[1])
        {
            _sntprintf(szFindPath, MAX_PATH, TEXT("%s\\*"), pszPath);
        }
        else
        {
            _sntprintf(szFindPath, MAX_PATH, TEXT("%s*"), pszPath);
        }

        szFindPath[MAX_PATH-1] = TEXT('\0');

        _tcsncpy(szBasePath, pszPath, MAX_PATH);
        szBasePath[MAX_PATH-1] = TEXT('\0');
    }
    else
    {
        _stprintf(szBasePath, TEXT("\\%s"), pszPath);
        _stprintf(szFindPath, TEXT("\\%s\\*"), pszPath);
    }

    hFind = FindFirstFile(szFindPath, &ffd);

    if (INVALID_HANDLE_VALUE != hFind)
    {
        bFoundFile = TRUE;
    }

    while (bFoundFile)
    {
        if (TEXT('\0') != szBasePath[0]
            && TEXT('\\') == szBasePath[_tcslen(szBasePath) - 1])
        {
            _stprintf(szFindPath, TEXT("%s%s"), szBasePath, ffd.cFileName);
        }
        else
        {
            _stprintf(szFindPath, TEXT("%s\\%s"), szBasePath, ffd.cFileName);
        }

        if (FILE_ATTRIBUTE_DIRECTORY & ffd.dwFileAttributes)
        {
            iCount += FindMediaFiles(szFindPath, pLocalContent, iCount);
        }

        if (!(FILE_ATTRIBUTE_HIDDEN & ffd.dwFileAttributes)
            && IsMediaFile(ffd.cFileName))
        {
            if (pLocalContent->InsertTrack(iCount + 1, szFindPath))
            {
                iCount++;
            }
        }

        bFoundFile = FindNextFile(hFind, &ffd);
    }

    if (INVALID_HANDLE_VALUE != hFind)
    {
        FindClose(hFind);
    }

    return iCount;
}

bool CPlaylistMgr::IsMediaFile(LPCTSTR pszFile)
{
    DWORD   i;
    TCHAR * pszExt  = _tcsrchr(pszFile, TEXT('.'));

    if (NULL == pszExt)
    {
        return false;
    }

    for (i = 0; i < g_cAudioTypes; i++)
    {
        if (0 == _tcsicmp(pszExt, g_ppszAudioTypes[i]))
        {
            return true;
        }
    }

    for (i = 0; i < g_cVideoTypes; i++)
    {
        if (0 == _tcsicmp(pszExt, g_ppszVideoTypes[i]))
        {
            return true;
        }
    }

    return false;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -