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

📄 medialibrarydlg.cpp

📁 WINCE 下的Media Player 播放器控制源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        break;
    }
    return 0;
}

/***********************************************************************
* ShowPlaylist
* pPlaylist: playlist object shown in the media list
* szMediaType: when it's not NULL, only media with this mediaType can be listed
* 
* ListBox has only about 64K memory to save data for strings, so this is
* not a good way to show large media library. So deal with large media
* library, use custom-drawn ListBox
***********************************************************************/
HRESULT CMediaLibraryDlg::ShowPlaylist(IWMPPlaylist* pPlaylist, TCHAR *szMediaType)
{
    if(pPlaylist == NULL)
    {
        return E_POINTER;
    }

    // Reset metadata list
    ::SendMessage(m_hMetadata, LB_RESETCONTENT, 0, 0);
    // Reset media list
    ::SendMessage(m_hList, LB_RESETCONTENT, 0, 0);

    // We always save the shown playlist for higher performance
    m_spSavedPlaylist = NULL;
    m_spSavedPlaylist = pPlaylist;

    HRESULT                 hr = E_POINTER;
    CComPtr<IWMPMedia>      spMedia;
    CComBSTR                bstrName, bstrType;
    long                    lCount(0), i(0), iListed(0);

    USES_CONVERSION;

    // Get count
    if(pPlaylist != NULL)
    {
        hr = pPlaylist->get_count(&lCount);
    }

    // Enumerate the items
    if(SUCCEEDED(hr))
    {
        for(i = 0; i < lCount; i++)
        {
            hr = pPlaylist->get_item(i, &spMedia);

            // If the media type is restricted, then we only show those items
            // with given type
            if(szMediaType != NULL)
            {
                if(SUCCEEDED(hr) && (spMedia.p != NULL))
                {
                    hr = spMedia->getItemInfo(CComBSTR(_T("MediaType")), &bstrType);
                }

                if(SUCCEEDED(hr) && (bstrType.m_str != NULL) && (!_tcsicmp(OLE2T(bstrType), szMediaType)))
                {
                    hr = spMedia->get_name(&bstrName);
                }
            }
            else
            {
                if(SUCCEEDED(hr) && (spMedia.p != NULL))
                {
                    hr = spMedia->get_name(&bstrName);
                }
            }

            // When bstrName is not NULL, we add the name to the media list
            if(SUCCEEDED(hr) && bstrName.m_str != NULL)
            {
                iListed++;
                ::SendMessage(m_hList, LB_ADDSTRING, 0, (LPARAM)OLE2T(bstrName));
                bstrName.Empty();
            }

            // Now we can release media object
            spMedia = NULL;
        }
    }

    // Show how many items in the media list
    TCHAR szLine[20];
    _stprintf(szLine, _T("%d items"), iListed);
    SetDlgItemText(IDC_STATUS, szLine);

    m_bIsShowingMedia = TRUE;
    return hr;
}

/***********************************************************************
* ShowPlaylist
* szPlaylistName: playlist name
* 
* This function use getByName to retrieve the playlist object
***********************************************************************/
HRESULT CMediaLibraryDlg::ShowPlaylist(TCHAR *szPlaylistName)
{
    HRESULT                     hr = E_POINTER;
    CComPtr<IWMPPlaylistArray>  spPlaylistArray;
    CComPtr<IWMPPlaylist>       spPlaylist;

    if(szPlaylistName != NULL)
    {
        hr = m_spPC->getByName(CComBSTR(szPlaylistName), &spPlaylistArray);
    }

    // In full application, it should consider the possibility that a My Playlist
    // and an auto playlist may have the same name, so it may need to distinguish 
    // and choose proper index of item
    // As a sample application, we use 0 to get the first item
    if(SUCCEEDED(hr) && (spPlaylistArray.p != NULL))
    {
        hr = spPlaylistArray->item(0, &spPlaylist);
    }
    if(SUCCEEDED(hr) && (spPlaylist.p != NULL))
    {
        ShowPlaylist(spPlaylist);
    }

    return hr;
}

/***********************************************************************
* ShowGetByAttr
* szAttrName: attribute name
* szAttrVal: attribute value
* szMediaType: media type
* 
* This function use getByAttribute() to retrieve the playlist object 
* that fullfil the conditions. It then show the playlist in the media list
***********************************************************************/
HRESULT CMediaLibraryDlg::ShowGetByAttr(TCHAR *szAttrName, TCHAR *szAttrVal, TCHAR *szMediaType)
{
    HRESULT                     hr;
    CComPtr<IWMPPlaylist>       spPlaylist;

    hr = m_spMC->getByAttribute(CComBSTR(szAttrName), CComBSTR(szAttrVal), &spPlaylist);
    if(SUCCEEDED(hr) && (spPlaylist.p != NULL))
    {
        hr = ShowPlaylist(spPlaylist, szMediaType);
    }

    return hr;
}

/***********************************************************************
* ShowAllMedia
* 
* This function shows all media in media list 
***********************************************************************/
HRESULT CMediaLibraryDlg::ShowAllMedia()
{
    HRESULT                 hr = S_OK;
    CComPtr<IWMPPlaylist>   spPlaylist;

    hr = m_spMC->getAll(&spPlaylist);
    if(SUCCEEDED(hr) && (spPlaylist.p != NULL))
    {
        hr = ShowPlaylist(spPlaylist);
    }

    return hr;
}

/***********************************************************************
* ShowNowPlaying
* 
* This function shows all media in current playlist 
***********************************************************************/
HRESULT CMediaLibraryDlg::ShowNowPlaying()
{
    HRESULT                 hr = E_POINTER;
    CComPtr<IWMPPlaylist>   spPlaylist;

    if(m_spPlayer.p != NULL)
    {
        hr = m_spPlayer->get_currentPlaylist(&spPlaylist);
    }

    if(SUCCEEDED(hr) && (spPlaylist.p != NULL))
    {
        hr = ShowPlaylist(spPlaylist);
    }

    return hr;
}

/***********************************************************************
* ShowAllMusic
* 
* This function shows all music items in media list 
***********************************************************************/
HRESULT CMediaLibraryDlg::ShowAllMusic()
{
    HRESULT                 hr = E_POINTER;
    CComPtr<IWMPPlaylist>   spPlaylist;

    if(m_spMC.p != NULL)
    {
        hr = m_spMC->getByAttribute(CComBSTR(_T("MediaType")), CComBSTR(_T("Audio")), &spPlaylist);
    }

    if(SUCCEEDED(hr) && (spPlaylist.p != NULL))
    {
        hr = ShowPlaylist(spPlaylist);
    }

    return hr;
}

/***********************************************************************
* ShowAllMusicTree
* 
* This function updates the All Music node and its sub-tree  
***********************************************************************/
HRESULT CMediaLibraryDlg::ShowAllMusicTree()
{
    HRESULT                 hr = S_OK;
    HTREEITEM               hPreChild, hCurChild;

    // Delete all child nodes
    hPreChild = TreeView_GetChild(m_hTree, m_hAllMusicNode);
    while(hPreChild != NULL)
    {
        hCurChild = hPreChild;
        hPreChild = TreeView_GetNextSibling(m_hTree, hPreChild);
        TreeView_DeleteItem(m_hTree, hCurChild);
    }

    // Now we add artist, album and genre nodes
    hr = ShowStringCollection(
        AddNode(_T("Artist"), TREE_MUSIC_ARTIST, m_hAllMusicNode), 
        TREE_MUSIC_ARTISTITEM, _T("Artist"), _T("Audio"));
    hr = ShowStringCollection(
        AddNode(_T("Album"), TREE_MUSIC_ALBUM, m_hAllMusicNode), 
        TREE_MUSIC_ALBUMITEM, _T("Album"), _T("Audio"));
    hr = ShowStringCollection(
        AddNode(_T("Genre"), TREE_MUSIC_GENRE, m_hAllMusicNode), 
        TREE_MUSIC_GENREITEM, _T("Genre"), _T("Audio"));

    return hr;
}

/***********************************************************************
* ShowAllVideo
* 
* This function shows all video items in media list 
***********************************************************************/
HRESULT CMediaLibraryDlg::ShowAllVideo()
{
    HRESULT                 hr = E_POINTER;
    CComPtr<IWMPPlaylist>   spPlaylist;

    if(m_spMC.p != NULL)
    {
        hr = m_spMC->getByAttribute(CComBSTR(_T("MediaType")), CComBSTR(_T("Video")), &spPlaylist);
    }

    if(SUCCEEDED(hr) && (spPlaylist.p != NULL))
    {
        hr = ShowPlaylist(spPlaylist);
    }

    return hr;
}

/***********************************************************************
* ShowAllVideoTree
* 
* This function updates the All Video node and its sub-tree  
***********************************************************************/
HRESULT CMediaLibraryDlg::ShowAllVideoTree()
{
    HRESULT                 hr = S_OK;
    HTREEITEM               hPreChild, hCurChild;

    // Delete all child nodes
    hPreChild = TreeView_GetChild(m_hTree, m_hAllVideoNode);
    while(hPreChild != NULL)
    {
        hCurChild = hPreChild;
        hPreChild = TreeView_GetNextSibling(m_hTree, hPreChild);
        TreeView_DeleteItem(m_hTree, hCurChild);
    }

    // Now we add actor and genre nodes
    ShowStringCollection(
        AddNode(_T("Actor"), TREE_VIDEO_ACTOR, m_hAllVideoNode), 
        TREE_VIDEO_ACTORITEM, _T("Actor"), _T("Video"));
    ShowStringCollection(
        AddNode(_T("Genre"), TREE_VIDEO_GENRE, m_hAllVideoNode), 
        TREE_VIDEO_GENREITEM, _T("Genre"), _T("Video"));

    return hr;
}

/***********************************************************************
* ShowPlaylistsTree
* 
* This function updates the My Playlists node and Auto Playlists node
***********************************************************************/
HRESULT CMediaLibraryDlg::ShowPlaylistsTree()
{
    // Remove child nodes
    HTREEITEM                   hPreChild, hCurChild;
    
    hPreChild = TreeView_GetChild(m_hTree, m_hMyPlaylistsNode);
    while(hPreChild != NULL)
    {
        hCurChild = hPreChild;
        hPreChild = TreeView_GetNextSibling(m_hTree, hPreChild);

⌨️ 快捷键说明

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