2011-05-21 18:17:37 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2011 Birunthan Mohanathas (www.poiru.net)
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-05-21 18:17:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "PlayerWMP.h"
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
Player* PlayerWMP::c_Player = nullptr;
|
2011-07-15 15:18:02 +00:00
|
|
|
extern HINSTANCE g_Instance;
|
2011-05-22 14:45:54 +00:00
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Definitions of ATL stuff we need to avoid dependency on atlbase.h (which is not included in free
|
|
|
|
// versions of Visual Studio).
|
|
|
|
|
|
|
|
MIDL_INTERFACE("B6EA2050-048A-11d1-82B9-00C04FB9942E")
|
|
|
|
IAxWinHostWindow : public IUnknown
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE CreateControl(
|
|
|
|
LPCOLESTR lpTricsData, HWND hWnd, IStream *pStream) = 0;
|
|
|
|
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE CreateControlEx(
|
|
|
|
LPCOLESTR lpszTricsData, HWND hWnd, IStream* pStream, IUnknown** ppUnk, REFIID iidAdvise,
|
|
|
|
IUnknown* punkSink) = 0;
|
|
|
|
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE AttachControl(IUnknown* pUnkControl, HWND hWnd) = 0;
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE QueryControl(REFIID riid, void** ppvObject) = 0;
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE SetExternalDispatch(IDispatch* pDisp) = 0;
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE SetExternalUIHandler(void* pDisp) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef BOOL (WINAPI * AtlAxWinInitFunc)();
|
|
|
|
typedef HRESULT (WINAPI * AtlAxGetControlFunc)(HWND h, IUnknown** pp);
|
|
|
|
typedef HRESULT (WINAPI * AtlAxGetHostFunc)(HWND h, IUnknown** pp);
|
|
|
|
|
|
|
|
HMODULE InitializeAtlLibrary()
|
|
|
|
{
|
|
|
|
static HMODULE s_ATL = LoadLibrary(L"atl");
|
|
|
|
if (s_ATL)
|
|
|
|
{
|
|
|
|
auto atlAxWinInit = (AtlAxWinInitFunc)GetProcAddress(s_ATL, "AtlAxWinInit");
|
|
|
|
atlAxWinInit();
|
|
|
|
}
|
|
|
|
return s_ATL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
//
|
2013-05-31 14:18:52 +00:00
|
|
|
// PlayerWMP::CRemoteHost
|
2013-05-09 10:23:52 +00:00
|
|
|
//
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
PlayerWMP::CRemoteHost::CRemoteHost() :
|
2013-05-09 10:23:52 +00:00
|
|
|
m_Player(),
|
|
|
|
m_RefCount(0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
PlayerWMP::CRemoteHost::~CRemoteHost()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
ULONG STDMETHODCALLTYPE PlayerWMP::CRemoteHost::AddRef()
|
2013-05-09 10:23:52 +00:00
|
|
|
{
|
|
|
|
++m_RefCount;
|
|
|
|
return m_RefCount;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
ULONG STDMETHODCALLTYPE PlayerWMP::CRemoteHost::Release()
|
2013-05-09 10:23:52 +00:00
|
|
|
{
|
|
|
|
--m_RefCount;
|
|
|
|
if (m_RefCount == 0)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return m_RefCount;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
HRESULT STDMETHODCALLTYPE PlayerWMP::CRemoteHost::QueryInterface(IID const& riid, void** object)
|
2013-05-09 10:23:52 +00:00
|
|
|
{
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown) ||
|
|
|
|
riid == __uuidof(IServiceProvider))
|
|
|
|
{
|
|
|
|
*object = (IServiceProvider*)this;
|
|
|
|
}
|
|
|
|
else if (riid == __uuidof(IWMPRemoteMediaServices))
|
|
|
|
{
|
|
|
|
*object = (IWMPRemoteMediaServices*)this;
|
|
|
|
}
|
|
|
|
else if (riid == __uuidof(IWMPEvents))
|
|
|
|
{
|
|
|
|
*object = (IWMPEvents*)this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
*object = nullptr;
|
2013-05-09 10:23:52 +00:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
HRESULT PlayerWMP::CRemoteHost::QueryService(REFGUID guidService, REFIID riid, void** ppv)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
return QueryInterface(riid, ppv);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
HRESULT PlayerWMP::CRemoteHost::GetServiceType(BSTR* pbstrType)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-02-22 14:34:57 +00:00
|
|
|
*pbstrType = SysAllocString(L"RemoteNoDialogs");
|
|
|
|
return *pbstrType ? S_OK : E_POINTER;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
HRESULT PlayerWMP::CRemoteHost::GetApplicationName(BSTR* pbstrName)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-02-22 14:34:57 +00:00
|
|
|
*pbstrName = SysAllocString(L"Rainmeter NowPlaying");
|
|
|
|
return *pbstrName ? S_OK : E_POINTER;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
HRESULT PlayerWMP::CRemoteHost::GetScriptableObject(BSTR* pbstrName, IDispatch** ppDispatch)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
if (pbstrName)
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
*pbstrName = nullptr;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
if (ppDispatch)
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
*ppDispatch = nullptr;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
HRESULT PlayerWMP::CRemoteHost::GetCustomUIMode(BSTR* pbstrFile)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Called when playing track changes.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::CRemoteHost::CurrentItemChange(IDispatch* pdispMedia)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-05-31 13:15:53 +00:00
|
|
|
m_Player->m_TrackChanged = true;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Called when play state changes.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::CRemoteHost::PlayStateChange(long NewState)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
switch (NewState)
|
|
|
|
{
|
|
|
|
case wmppsStopped:
|
|
|
|
case wmppsMediaEnded:
|
2012-04-18 16:10:43 +00:00
|
|
|
m_Player->ClearData(false);
|
2011-05-21 18:17:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case wmppsPaused:
|
2012-01-08 17:35:29 +00:00
|
|
|
m_Player->m_State = STATE_PAUSED;
|
2011-05-21 18:17:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case wmppsPlaying:
|
2012-01-08 17:35:29 +00:00
|
|
|
if (m_Player->m_State == STATE_STOPPED)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-05-31 13:15:53 +00:00
|
|
|
m_Player->m_TrackChanged = true;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
m_Player->m_State = STATE_PLAYING;
|
2011-05-21 18:17:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Called when WMP quits.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::CRemoteHost::SwitchedToControl()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
m_Player->ClearData();
|
2011-05-31 13:15:53 +00:00
|
|
|
m_Player->Uninitialize();
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
//
|
2013-05-31 14:18:52 +00:00
|
|
|
// PlayerWMP
|
2013-05-09 10:23:52 +00:00
|
|
|
//
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
PlayerWMP::PlayerWMP() : Player(),
|
2011-06-17 19:07:06 +00:00
|
|
|
m_TrackChanged(false),
|
|
|
|
m_Window(),
|
2011-10-12 13:34:04 +00:00
|
|
|
m_LastCheckTime(0),
|
2013-05-09 10:23:52 +00:00
|
|
|
m_ConnectionCookie()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
PlayerWMP::~PlayerWMP()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
c_Player = nullptr;
|
2011-05-21 18:17:37 +00:00
|
|
|
Uninitialize();
|
|
|
|
}
|
|
|
|
|
2011-06-19 14:58:48 +00:00
|
|
|
/*
|
|
|
|
** Creates a shared class object.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
Player* PlayerWMP::Create()
|
2011-06-19 14:58:48 +00:00
|
|
|
{
|
|
|
|
if (!c_Player)
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
c_Player = new PlayerWMP();
|
2011-06-19 14:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c_Player;
|
|
|
|
}
|
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
/*
|
|
|
|
** Set up the COM interface with WMP.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::Initialize()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
HMODULE atl = InitializeAtlLibrary();
|
|
|
|
if (!atl)
|
|
|
|
{
|
|
|
|
RmLog(LOG_ERROR, L"NowPlaying: ATL not found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto atlAxGetControl = (AtlAxGetControlFunc)GetProcAddress(atl, "AtlAxGetControl");
|
|
|
|
auto atlAxGetHost = (AtlAxGetHostFunc)GetProcAddress(atl, "AtlAxGetHost");
|
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
WNDCLASS wc = {0};
|
2011-07-15 15:18:02 +00:00
|
|
|
wc.hInstance = g_Instance;
|
2011-05-21 18:17:37 +00:00
|
|
|
wc.lpfnWndProc = DefWindowProc;
|
2013-05-09 10:23:52 +00:00
|
|
|
wc.lpszClassName = L"NowPlayingWMP";
|
2011-05-21 18:17:37 +00:00
|
|
|
RegisterClass(&wc);
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
// Create the container window and the ATL host window.
|
|
|
|
m_Window = CreateWindow(
|
|
|
|
L"NowPlayingWMP", L"",
|
|
|
|
WS_DISABLED,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
2013-05-31 14:28:39 +00:00
|
|
|
nullptr, nullptr, g_Instance, nullptr);
|
2013-05-09 10:23:52 +00:00
|
|
|
|
|
|
|
HWND window = CreateWindow(
|
|
|
|
L"AtlAxWin", L"",
|
|
|
|
WS_DISABLED | WS_CHILD,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
2013-05-31 14:28:39 +00:00
|
|
|
m_Window, nullptr, g_Instance, nullptr);
|
2013-05-09 10:23:52 +00:00
|
|
|
|
|
|
|
Microsoft::WRL::ComPtr<IUnknown> axHost;
|
|
|
|
Microsoft::WRL::ComPtr<IObjectWithSite> hostObject;
|
|
|
|
HRESULT hr = atlAxGetHost(window, axHost.GetAddressOf());
|
|
|
|
if (SUCCEEDED(hr))
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = axHost.As(&hostObject);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2013-05-09 10:23:52 +00:00
|
|
|
|
|
|
|
Microsoft::WRL::ComPtr<CRemoteHost> remoteHost(new CRemoteHost());
|
|
|
|
if (SUCCEEDED(hr))
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
remoteHost->m_Player = this;
|
|
|
|
hr = hostObject->SetSite((IWMPRemoteMediaServices*)remoteHost.Get());
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
Microsoft::WRL::ComPtr<IAxWinHostWindow> axWinHostWindow;
|
2011-05-21 18:17:37 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = axHost.As(&axWinHostWindow);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = axWinHostWindow->CreateControl(L"{6BF52A52-394A-11D3-B153-00C04F79FAA6}", window, nullptr);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
Microsoft::WRL::ComPtr<IUnknown> axControl;
|
2011-05-21 18:17:37 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = atlAxGetControl(window, axControl.GetAddressOf());
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = axControl.As(&m_IPlayer);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
// Connect the event interface.
|
|
|
|
Microsoft::WRL::ComPtr<IConnectionPointContainer> wmpPlayerConnectionContainer;
|
2011-05-21 18:17:37 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = m_IPlayer.As(&wmpPlayerConnectionContainer);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = wmpPlayerConnectionContainer->FindConnectionPoint(
|
|
|
|
__uuidof(IWMPEvents), m_IConnectionPoint.GetAddressOf());
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = m_IConnectionPoint->Advise(remoteHost->GetUnknown(), &m_ConnectionCookie);
|
|
|
|
if (!m_ConnectionCookie)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = E_FAIL;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
if (SUCCEEDED(hr))
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = m_IPlayer->get_controls(&m_IControls);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
if (SUCCEEDED(hr))
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
hr = m_IPlayer->get_settings(&m_ISettings);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2013-05-09 10:23:52 +00:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
WMPPlayState state;
|
|
|
|
m_IPlayer->get_playState(&state);
|
|
|
|
if (state == wmppsPlaying)
|
|
|
|
{
|
|
|
|
m_State = STATE_PLAYING;
|
|
|
|
}
|
|
|
|
else if (state == wmppsPaused)
|
|
|
|
{
|
|
|
|
m_State = STATE_PAUSED;
|
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
if (m_State != STATE_STOPPED)
|
|
|
|
{
|
|
|
|
m_TrackChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Initialized = true;
|
|
|
|
}
|
|
|
|
else
|
2011-06-12 10:05:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
Uninitialize();
|
2011-06-12 10:05:37 +00:00
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Close the interface with WMP.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::Uninitialize()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
if (m_Initialized)
|
|
|
|
{
|
|
|
|
m_Initialized = false;
|
2013-05-09 10:23:52 +00:00
|
|
|
|
|
|
|
if (m_ConnectionCookie)
|
|
|
|
{
|
|
|
|
m_IConnectionPoint->Unadvise(m_ConnectionCookie);
|
|
|
|
m_ConnectionCookie = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_IControls.Reset();
|
|
|
|
m_ISettings.Reset();
|
|
|
|
m_IConnectionPoint.Reset();
|
|
|
|
m_IPlayer.Reset();
|
2011-05-21 18:17:37 +00:00
|
|
|
DestroyWindow(m_Window);
|
2013-05-09 10:34:29 +00:00
|
|
|
UnregisterClass(L"NowPlayingWMP", g_Instance);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Called during each update of the main measure.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::UpdateData()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
if (m_Initialized)
|
|
|
|
{
|
|
|
|
// Get the volume
|
|
|
|
long volume;
|
|
|
|
m_ISettings->get_volume(&volume);
|
|
|
|
m_Volume = (UINT)volume;
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
if (m_State != STATE_STOPPED)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
double position;
|
|
|
|
m_IControls->get_currentPosition(&position);
|
|
|
|
m_Position = (UINT)position;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_TrackChanged)
|
|
|
|
{
|
|
|
|
m_TrackChanged = false;
|
2011-06-17 19:07:06 +00:00
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
Microsoft::WRL::ComPtr<IWMPMedia> spMedia;
|
|
|
|
m_IPlayer->get_currentMedia(spMedia.GetAddressOf());
|
2011-05-21 18:17:37 +00:00
|
|
|
|
|
|
|
if (spMedia)
|
|
|
|
{
|
2012-02-22 14:34:57 +00:00
|
|
|
BSTR val;
|
2013-05-09 10:23:52 +00:00
|
|
|
|
|
|
|
spMedia->getItemInfo(_bstr_t(L"Artist"), &val);
|
2011-05-21 18:17:37 +00:00
|
|
|
m_Artist = val;
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
spMedia->getItemInfo(_bstr_t(L"Title"), &val);
|
2011-05-21 18:17:37 +00:00
|
|
|
m_Title = val;
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
spMedia->getItemInfo(_bstr_t(L"Album"), &val);
|
2011-05-21 18:17:37 +00:00
|
|
|
m_Album = val;
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
spMedia->getItemInfo(_bstr_t(L"UserRating"), &val);
|
2011-05-21 18:17:37 +00:00
|
|
|
int rating = _wtoi(val);
|
|
|
|
|
|
|
|
if (rating > 75)
|
|
|
|
{
|
|
|
|
m_Rating = 5;
|
|
|
|
}
|
|
|
|
else if (rating > 50)
|
|
|
|
{
|
|
|
|
m_Rating = 4;
|
|
|
|
}
|
|
|
|
else if (rating > 25)
|
|
|
|
{
|
|
|
|
m_Rating = 3;
|
|
|
|
}
|
|
|
|
else if (rating > 1)
|
|
|
|
{
|
|
|
|
m_Rating = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Rating = rating;
|
|
|
|
}
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
spMedia->getItemInfo(_bstr_t(L"WM/TrackNumber"), &val);
|
2012-03-12 12:01:12 +00:00
|
|
|
m_Number = (UINT)_wtoi(val);
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
spMedia->getItemInfo(_bstr_t(L"WM/Year"), &val);
|
2012-03-12 12:01:12 +00:00
|
|
|
m_Year = (UINT)_wtoi(val);
|
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
double duration;
|
|
|
|
spMedia->get_duration(&duration);
|
|
|
|
m_Duration = (UINT)duration;
|
|
|
|
|
2012-02-22 14:34:57 +00:00
|
|
|
BSTR url;
|
2011-05-22 08:06:43 +00:00
|
|
|
spMedia->get_sourceURL(&url);
|
|
|
|
std::wstring targetPath = url;
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2011-05-22 08:06:43 +00:00
|
|
|
if (targetPath != m_FilePath)
|
|
|
|
{
|
2012-02-22 14:34:57 +00:00
|
|
|
++m_TrackCount;
|
2011-05-22 08:06:43 +00:00
|
|
|
m_FilePath = targetPath;
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
// Find cover if needed
|
|
|
|
// TODO: Fix temp solution
|
2011-09-08 12:42:03 +00:00
|
|
|
if (m_Measures & MEASURE_COVER || m_InstanceCount == 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
spMedia->getItemInfo(_bstr_t(L"WM/WMCollectionID"), &val);
|
2011-05-22 08:06:43 +00:00
|
|
|
targetPath.resize(targetPath.find_last_of(L'\\') + 1);
|
|
|
|
targetPath += L"AlbumArt_";
|
|
|
|
targetPath += val;
|
|
|
|
targetPath += L"_Large.jpg";
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2011-05-22 08:06:43 +00:00
|
|
|
if (_waccess(targetPath.c_str(), 0) == 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-05-22 08:06:43 +00:00
|
|
|
m_CoverPath = targetPath;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2011-05-22 08:06:43 +00:00
|
|
|
else
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-19 14:58:48 +00:00
|
|
|
FindCover();
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-19 14:58:48 +00:00
|
|
|
|
2011-09-08 12:42:03 +00:00
|
|
|
if (m_Measures & MEASURE_LYRICS)
|
2011-06-19 14:58:48 +00:00
|
|
|
{
|
|
|
|
FindLyrics();
|
|
|
|
}
|
2011-05-22 08:06:43 +00:00
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD time = GetTickCount();
|
|
|
|
|
|
|
|
// Try to find WMP window every 5 seconds
|
2011-10-12 13:34:04 +00:00
|
|
|
if (m_LastCheckTime = 0 || time - m_LastCheckTime > 5000)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-10-12 13:34:04 +00:00
|
|
|
m_LastCheckTime = time;
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
if (FindWindow(L"WMPlayerApp", nullptr))
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-09 09:47:55 +00:00
|
|
|
/*
|
|
|
|
** Handles the Pause bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::Pause()
|
2011-06-09 09:47:55 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
m_IControls->pause();
|
2011-06-09 09:47:55 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
/*
|
|
|
|
** Handles the Play bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::Play()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
m_IControls->play();
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the Stop bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::Stop()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
m_IControls->stop();
|
|
|
|
// TODO: FIXME
|
2012-01-08 17:35:29 +00:00
|
|
|
m_State = STATE_STOPPED;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the Next bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::Next()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
m_IControls->next();
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the Previous bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::Previous()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
m_IControls->previous();
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-09 09:47:55 +00:00
|
|
|
/*
|
|
|
|
** Handles the SetPosition bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::SetPosition(int position)
|
2011-06-09 09:47:55 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
m_IControls->put_currentPosition((double)position);
|
2011-06-09 09:47:55 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
/*
|
|
|
|
** Handles the SetRating bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::SetRating(int rating)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
if (m_State != STATE_STOPPED)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-09 10:23:52 +00:00
|
|
|
Microsoft::WRL::ComPtr<IWMPMedia> spMedia;
|
|
|
|
m_IPlayer->get_currentMedia(spMedia.GetAddressOf());
|
2011-05-21 18:17:37 +00:00
|
|
|
|
|
|
|
if (spMedia)
|
|
|
|
{
|
2012-02-22 14:34:57 +00:00
|
|
|
BSTR val;
|
2011-09-11 08:22:07 +00:00
|
|
|
switch (rating)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-09-11 08:22:07 +00:00
|
|
|
case 0:
|
2011-05-21 18:17:37 +00:00
|
|
|
val = L"0";
|
2011-09-11 08:22:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2011-05-21 18:17:37 +00:00
|
|
|
val = L"1";
|
2011-09-11 08:22:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2011-05-21 18:17:37 +00:00
|
|
|
val = L"25";
|
2011-09-11 08:22:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2011-05-21 18:17:37 +00:00
|
|
|
val = L"50";
|
2011-09-11 08:22:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2011-05-21 18:17:37 +00:00
|
|
|
val = L"75";
|
2011-09-11 08:22:07 +00:00
|
|
|
break;
|
|
|
|
|
2012-02-22 14:34:57 +00:00
|
|
|
default: // case 5:
|
2011-05-21 18:17:37 +00:00
|
|
|
val = L"99";
|
2011-09-11 08:22:07 +00:00
|
|
|
break;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 10:23:52 +00:00
|
|
|
spMedia->setItemInfo(_bstr_t(L"UserRating"), val);
|
2011-05-21 18:17:37 +00:00
|
|
|
m_Rating = rating;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the SetVolume bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::SetVolume(int volume)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
m_ISettings->put_volume(volume);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the ClosePlayer bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::ClosePlayer()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
HWND wnd = FindWindow(L"WMPlayerApp", nullptr);
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
if (wnd)
|
|
|
|
{
|
|
|
|
SendMessage(wnd, WM_CLOSE, 0, 0);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the OpenPlayer bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWMP::OpenPlayer(std::wstring& path)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
ShellExecute(nullptr, L"open", path.empty() ? L"wmplayer.exe" : path.c_str(), nullptr, nullptr, SW_SHOW);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|