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

📄 plist.cpp

📁 media player 控件源码 用EVC编译可以进行对WINCE下media player控制
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// plist.cpp
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <uuids.h>
#include <playlist.h>

#include "plist.h"

const char c_szASXHeaderFormat[] = "<ASX version = \"3.0\">\n"
                                   "    <PARAM name = \"Last Entry\" value = \"%d\"/>\n"
                                   "    <PARAM name = \"Generator\" value = \"CEPlayer\"/>\n";
const char c_szASXEntryFormat[]  = "    <ENTRY>\n"
                                   "        <REF href=\"%s\"/>\n"
                                   "    </ENTRY>\n";
const char c_szASXFooterFormat[] = "</ASX>\n";

CMediaClip::CMediaClip() : m_pszTitle(NULL), m_pszPath(NULL), m_cRef(0), m_eLocation(LOCAL)
{
}

CMediaClip::~CMediaClip()
{
    delete [] m_pszTitle;
    delete [] m_pszPath;
}

bool CMediaClip::SetLocation(LPCTSTR pszPath)
{
    if (NULL != m_pszPath)
    {
        delete [] m_pszPath;
    }

    // strip out a "file://" if it's there
    TCHAR * pszTemp = _tcsstr(pszPath, TEXT("://"));

    if (pszTemp
        && _tcslen(pszPath) > 7
        && TEXT('F') == toupper(pszPath[0])
        && TEXT('I') == toupper(pszPath[1])
        && TEXT('L') == toupper(pszPath[2])
        && TEXT('E') == toupper(pszPath[3]))
    {
        pszPath = pszTemp + _tcslen(TEXT("://"));
    }

    m_pszPath = new TCHAR [_tcslen(pszPath)+1];

    if (m_pszPath && _tcslen(pszPath) > 1)
    {
        _tcscpy(m_pszPath, pszPath);
    }
    else if (m_pszPath)
    {
        delete [] m_pszPath;
        m_pszPath = NULL;

        return false;
    }
    else
    {
        return false;
    }

    // if path is of the form "\\blah..." or "blah://" then call it
    // a network file.
    if ((TEXT('\\') == m_pszPath[0] && TEXT('\\') == m_pszPath[1])
        || NULL != _tcsstr(m_pszPath, TEXT("://")))
    {
        m_eLocation = NETWORK;
    }
    else
    {
        LPTSTR pszSlash;
        DWORD dwAttrib;

        m_eLocation = LOCAL;

        pszSlash = _tcschr(m_pszPath + 1, TEXT('\\'));

        if (pszSlash)
        {
            *pszSlash = TEXT('\0');

            dwAttrib = GetFileAttributes(m_pszPath);

            if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY 
                && dwAttrib & FILE_ATTRIBUTE_TEMPORARY)
            {
                m_eLocation = STORAGECARD;
            }

            *pszSlash = TEXT('\\');
        }

        dwAttrib = GetFileAttributes(m_pszPath);

        if (STORAGECARD != m_eLocation
            && 0xffffffff == dwAttrib)
        {
            delete [] m_pszPath;
            m_pszPath = NULL;

            return false;
        }
    }

    m_pszArtist = new TCHAR [_tcslen(TEXT("Unknown")) + 1];
    _tcscpy(m_pszArtist, TEXT("Unknown"));

    if (NETWORK != m_eLocation)
    {
        LPTSTR pszSlash;

        pszSlash = _tcsrchr(m_pszPath, TEXT('\\'));

        if (NULL == pszSlash)
        {
            pszSlash = m_pszPath;
        }
        else
        {
            pszSlash++;
        }

        m_pszTitle = new TCHAR[_tcslen(pszSlash) + 1];
        _tcscpy(m_pszTitle, pszSlash);
    }
    else
    {
        LPTSTR pszSlash;

        // if the title begins with "\" it's a network share, otherwise,
        // assume it's a URL
        if (TEXT('\\') == m_pszPath[0])
        {
            pszSlash = _tcsrchr(m_pszPath, TEXT('\\'));
        }
        else
        {
            pszSlash = _tcsrchr(m_pszPath, TEXT('/'));
        }

        if (NULL == pszSlash)
        {
            pszSlash = m_pszPath;
        }
        else
        {
            pszSlash++;
        }

        m_pszTitle = new TCHAR[_tcslen(pszSlash) + 1];
        _tcscpy(m_pszTitle, pszSlash);
    }

    return true;
}

LPCTSTR CMediaClip::GetTitle() const
{
    return m_pszTitle;
}

LPCTSTR CMediaClip::GetArtist() const
{
    return m_pszArtist;
}

LPCTSTR CMediaClip::GetPath() const
{
    return m_pszPath;
}

EFileLocation CMediaClip::GetLocation() const
{
    return m_eLocation;
}

bool CMediaClip::IsLocal() const
{
    return (m_eLocation == LOCAL || m_eLocation == STORAGECARD);
}

bool CMediaClip::IsAvailable() const
{
    if (NETWORK != m_eLocation)
    {
        DWORD dwAttrib;

        dwAttrib = GetFileAttributes(m_pszPath);

        return (0xffffffff != dwAttrib ? true : false);
    }
    else
    {
        return true;
    }
}

CPlaylist::CPlaylist(LPCTSTR pszPath) :
    m_pszPath(NULL),
    m_pszName(NULL),
    m_pList(NULL),
    m_iCurrentTrack(-1),
    m_uCount(0),
    m_bCEPlaylist(false),
    m_bHidden(false),
    m_bTransient(false)
{
    TCHAR * pszName = NULL,
          * pszExt  = NULL;

    if (pszPath)
    {
        m_pszPath = new TCHAR [_tcslen(pszPath) + 1];

        if (m_pszPath)
        {
            _tcscpy(m_pszPath, pszPath);

            GetNameFromPath(m_pszPath, &m_pszName);
        }
    }
}

CPlaylist::~CPlaylist()
{
    playlist_t * pTemp = m_pList;

    while (NULL != m_pList)
    {
        m_pList = m_pList->pNext;

        delete pTemp;

        pTemp = m_pList;
    }

    delete [] m_pszPath;
}

bool CPlaylist::GetNameFromPath(LPTSTR szPath, LPTSTR* pszName)
{
	TCHAR * szName = NULL,
          * szExt  = NULL;
	LONG  length=0;

	ASSERT(szPath && !*pszName);

	szName = _tcsrchr(szPath, TEXT('\\'));
	szExt  = _tcsrchr(szPath, TEXT('.'));

	if (!szName)
	{
		szName = szPath;
	}
	else
	{
		szName++;
	}

	if (szExt)
		*szExt = TEXT('\0');
	
	if( szName && szName[0] )
	{
		length = _tcslen(szName);
	}

	*pszName = new TCHAR[length + 1];
	if (*pszName)
		_tcscpy(*pszName, szName);

	if (szExt)
		*szExt = TEXT('.');

	return (*pszName ? true : false);
}

bool CPlaylist::InsertTrack(UINT uPos, LPCTSTR pszLocation)
{
    // uPos is 0 based
    // If uPos is larger than the length of the playlist,
    // append it to the end of the list.

    playlist_t * pTemp = m_pList;

    for (UINT i = 0; i < uPos; i++)
    {
        if (NULL != pTemp
            && NULL != pTemp->pNext)
        {
            pTemp = pTemp->pNext;
        }
        else
        {
            break;
        }
    }

    // insert after the pTemp pointer
    if (NULL != pTemp)
    {
        playlist_t * pNew = new playlist_t;

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

        pNew->pClip = new CMediaClip;

        if (NULL == pNew->pClip)
        {
            delete pNew;
            return false;
        }

        if (false == pNew->pClip->SetLocation(pszLocation))
        {
            delete pNew;
            return false;
        }

        pNew->pNext = pTemp->pNext;
        pNew->pPrev = pTemp;

        pTemp->pNext = pNew;
    }
    else
    {
        // insert at the front of the list
        pTemp = new playlist_t;

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

        pTemp->pClip = new CMediaClip;

        if (NULL == pTemp->pClip)
        {
            delete pTemp;
            return false;
        }

        if (false == pTemp->pClip->SetLocation(pszLocation))
        {
            delete pTemp;
            return false;
        }

        pTemp->pNext = m_pList;
        m_pList = pTemp;
    }

    m_uCount++;

    // adjust current index pointer
    if (uPos > m_uCount - 1)
    	uPos = m_uCount - 1;

    if (0 <= m_iCurrentTrack 
        && (UINT)m_iCurrentTrack >= uPos)
    {
    	if ((UINT)m_iCurrentTrack + 1 <= m_uCount - 1)
            m_iCurrentTrack++;
    }

    return true;
}

bool CPlaylist::DeleteTrack(UINT uPos)
{
    // uPos is 0 based
    playlist_t * pTemp, * pPrev, * pNext;
    bool bResult = false;

    pPrev = NULL;
    pTemp = m_pList;

    for (UINT i = 0; i < uPos; i++)
    {
        if (pTemp)
        {
            pPrev = pTemp;
            pTemp = pTemp->pNext;
        }
    }

    if (pTemp)
    {
        pNext = pTemp->pNext;

        if (pNext)
        {
            pNext->pPrev = pPrev;
        }

        if (pPrev)
        {
           pPrev->pNext = pNext;
        }
        else
        {
            m_pList = pNext;
        }

        delete pTemp;
		m_uCount--;

        bResult = true;
    }

    // adjust current index pointer
    if (0 <= m_iCurrentTrack 
    	&& (UINT)m_iCurrentTrack >= uPos)
    {
    	if ((UINT)m_iCurrentTrack > m_uCount - 1)
    		m_iCurrentTrack = m_uCount - 1;
    	else if ((UINT)m_iCurrentTrack != uPos)
    		m_iCurrentTrack--;
    }

    return bResult;
}

void CPlaylist::DeleteAll()
{
    playlist_t * pTemp = m_pList;

    while (NULL != m_pList)
    {
        m_pList = m_pList->pNext;

        delete pTemp;

        pTemp = m_pList;
    }
	m_uCount = 0;
}

bool CPlaylist::ShiftTrackUp(UINT uIndex)
{
    UINT         uPos    = 0;
    playlist_t * pCurr   = m_pList;

    if (0 == uIndex)
    {
        return false;
    }

    while (uPos < (uIndex - 1)
           && NULL != pCurr)
    {
        uPos++;

        pCurr = pCurr->pNext;
    }

    if (NULL == pCurr || NULL == pCurr->pNext || uPos < (uIndex - 1))
    {
        return false;
    }

    SwapItems(pCurr);

    if ((UINT)m_iCurrentTrack + 1 == uIndex)
        m_iCurrentTrack++;
    else if ((UINT)m_iCurrentTrack == uIndex)
    	m_iCurrentTrack--;

    return true;
}

bool CPlaylist::ShiftTrackDown(UINT uIndex)
{
    UINT         uPos    = 0;
    playlist_t * pCurr   = m_pList;

    while (uPos < uIndex
           && NULL != pCurr)
    {
        uPos++;

        pCurr = pCurr->pNext;
    }

    if (NULL == pCurr || NULL == pCurr->pNext || uPos < uIndex)
    {
        return false;
    }

    SwapItems(pCurr);

⌨️ 快捷键说明

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