player.c 65.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright 2014 Jacek Caban for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "wmp_private.h"

#include "wine/debug.h"
22
#include <nserror.h>
23
#include "wmpids.h"
24 25 26

WINE_DEFAULT_DEBUG_CHANNEL(wmp);

27 28 29 30
static ATOM player_msg_class;
static INIT_ONCE class_init_once;
static UINT WM_WMPEVENT;
static const WCHAR WMPmessageW[] = {'_', 'W', 'M', 'P', 'M','e','s','s','a','g','e',0};
31
static const WCHAR emptyW[] = {0};
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
static void update_state(WindowsMediaPlayer *wmp, LONG type, LONG state)
{
    DISPPARAMS dispparams;
    VARIANTARG params[1];

    dispparams.cArgs = 1;
    dispparams.cNamedArgs = 0;
    dispparams.rgdispidNamedArgs = NULL;
    dispparams.rgvarg = params;

    V_VT(params) = VT_UI4;
    V_UI4(params) = state;

    call_sink(wmp->wmpocx, type, &dispparams);
}

49 50 51 52 53
static inline WMPMedia *impl_from_IWMPMedia(IWMPMedia *iface)
{
    return CONTAINING_RECORD(iface, WMPMedia, IWMPMedia_iface);
}

54 55 56 57 58
static inline WindowsMediaPlayer *impl_from_IWMPNetwork(IWMPNetwork *iface)
{
    return CONTAINING_RECORD(iface, WindowsMediaPlayer, IWMPNetwork_iface);
}

59 60 61 62 63
static inline WindowsMediaPlayer *impl_from_IWMPPlayer4(IWMPPlayer4 *iface)
{
    return CONTAINING_RECORD(iface, WindowsMediaPlayer, IWMPPlayer4_iface);
}

64 65 66 67 68
static inline WindowsMediaPlayer *impl_from_IWMPPlayer(IWMPPlayer *iface)
{
    return CONTAINING_RECORD(iface, WindowsMediaPlayer, IWMPPlayer_iface);
}

69 70 71 72 73
static inline WindowsMediaPlayer *impl_from_IWMPControls(IWMPControls *iface)
{
    return CONTAINING_RECORD(iface, WindowsMediaPlayer, IWMPControls_iface);
}

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
static HRESULT WINAPI WMPPlayer4_QueryInterface(IWMPPlayer4 *iface, REFIID riid, void **ppv)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    return IOleObject_QueryInterface(&This->IOleObject_iface, riid, ppv);
}

static ULONG WINAPI WMPPlayer4_AddRef(IWMPPlayer4 *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    return IOleObject_AddRef(&This->IOleObject_iface);
}

static ULONG WINAPI WMPPlayer4_Release(IWMPPlayer4 *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    return IOleObject_Release(&This->IOleObject_iface);
}

static HRESULT WINAPI WMPPlayer4_GetTypeInfoCount(IWMPPlayer4 *iface, UINT *pctinfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_GetTypeInfo(IWMPPlayer4 *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_GetIDsOfNames(IWMPPlayer4 *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_Invoke(IWMPPlayer4 *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_close(IWMPPlayer4 *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

132
static HRESULT WINAPI WMPPlayer4_get_URL(IWMPPlayer4 *iface, BSTR *url)
133 134
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
135 136 137

    TRACE("(%p)->(%p)\n", This, url);

138 139
    if (!This->media)
        return return_bstr(emptyW, url);
140 141

    return return_bstr(This->media->url, url);
142 143 144 145 146
}

static HRESULT WINAPI WMPPlayer4_put_URL(IWMPPlayer4 *iface, BSTR url)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
147
    IWMPMedia *media;
148
    HRESULT hres;
149

150
    TRACE("(%p)->(%s)\n", This, debugstr_w(url));
151

152
    hres = create_media_from_url(url, 0.0, &media);
153

154
    if (SUCCEEDED(hres)) {
155
        update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsTransitioning);
156 157 158
        hres = IWMPPlayer4_put_currentMedia(iface, media);
        IWMPMedia_Release(media); /* put will addref */
    }
159 160
    if (SUCCEEDED(hres)) {
        update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsReady);
161 162
        if (This->auto_start == VARIANT_TRUE)
            IWMPControls_play(&This->IWMPControls_iface);
163
    }
164

165
    return hres;
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
}

static HRESULT WINAPI WMPPlayer4_get_openState(IWMPPlayer4 *iface, WMPOpenState *pwmpos)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pwmpos);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_playState(IWMPPlayer4 *iface, WMPPlayState *pwmpps)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pwmpps);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_controls(IWMPPlayer4 *iface, IWMPControls **ppControl)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
185 186 187 188 189 190

    TRACE("(%p)->(%p)\n", This, ppControl);

    IWMPControls_AddRef(&This->IWMPControls_iface);
    *ppControl = &This->IWMPControls_iface;
    return S_OK;
191 192 193 194 195
}

static HRESULT WINAPI WMPPlayer4_get_settings(IWMPPlayer4 *iface, IWMPSettings **ppSettings)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
196 197 198 199 200 201

    TRACE("(%p)->(%p)\n", This, ppSettings);

    IWMPSettings_AddRef(&This->IWMPSettings_iface);
    *ppSettings = &This->IWMPSettings_iface;
    return S_OK;
202 203
}

204
static HRESULT WINAPI WMPPlayer4_get_currentMedia(IWMPPlayer4 *iface, IWMPMedia **media)
205 206
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
207 208 209 210 211 212

    TRACE("(%p)->(%p)\n", This, media);

    *media = NULL;

    if (This->media == NULL)
213
        return S_FALSE;
214 215

    return create_media_from_url(This->media->url, This->media->duration, media);
216 217 218 219 220
}

static HRESULT WINAPI WMPPlayer4_put_currentMedia(IWMPPlayer4 *iface, IWMPMedia *pMedia)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
221
    TRACE("(%p)->(%p)\n", This, pMedia);
222

223 224 225
    if(pMedia == NULL) {
        return E_POINTER;
    }
226
    update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposPlaylistChanging);
227
    if(This->media != NULL) {
228
        IWMPControls_stop(&This->IWMPControls_iface);
229
        IWMPMedia_Release(&This->media->IWMPMedia_iface);
230
    }
231 232 233
    update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposPlaylistChanged);
    update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposPlaylistOpenNoMedia);

234
    IWMPMedia_AddRef(pMedia);
235
    This->media = unsafe_impl_from_IWMPMedia(pMedia);
236
    return S_OK;
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
}

static HRESULT WINAPI WMPPlayer4_get_mediaCollection(IWMPPlayer4 *iface, IWMPMediaCollection **ppMediaCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppMediaCollection);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_playlistCollection(IWMPPlayer4 *iface, IWMPPlaylistCollection **ppPlaylistCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppPlaylistCollection);
    return E_NOTIMPL;
}

253
static HRESULT WINAPI WMPPlayer4_get_versionInfo(IWMPPlayer4 *iface, BSTR *version)
254
{
255
    static const WCHAR versionW[] = {'1','2','.','0','.','7','6','0','1','.','1','6','9','8','2',0};
256
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
257 258 259 260 261 262

    TRACE("(%p)->(%p)\n", This, version);

    if (!version)
        return E_POINTER;

263
    return return_bstr(versionW, version);
264 265 266 267 268 269 270 271 272 273 274 275
}

static HRESULT WINAPI WMPPlayer4_launchURL(IWMPPlayer4 *iface, BSTR url)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(url));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_network(IWMPPlayer4 *iface, IWMPNetwork **ppQNI)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
276 277 278 279 280
    TRACE("(%p)->(%p)\n", This, ppQNI);

    IWMPNetwork_AddRef(&This->IWMPNetwork_iface);
    *ppQNI = &This->IWMPNetwork_iface;
    return S_OK;
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
}

static HRESULT WINAPI WMPPlayer4_get_currentPlaylist(IWMPPlayer4 *iface, IWMPPlaylist **ppPL)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppPL);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_currentPlaylist(IWMPPlayer4 *iface, IWMPPlaylist *pPL)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pPL);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_cdromCollection(IWMPPlayer4 *iface, IWMPCdromCollection **ppCdromCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppCdromCollection);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_closedCaption(IWMPPlayer4 *iface, IWMPClosedCaption **ppClosedCaption)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppClosedCaption);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_isOnline(IWMPPlayer4 *iface, VARIANT_BOOL *pfOnline)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pfOnline);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_Error(IWMPPlayer4 *iface, IWMPError **ppError)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppError);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_Status(IWMPPlayer4 *iface, BSTR *pbstrStatus)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pbstrStatus);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_dvd(IWMPPlayer4 *iface, IWMPDVD **ppDVD)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppDVD);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_newPlaylist(IWMPPlayer4 *iface, BSTR name, BSTR url, IWMPPlaylist **ppPlaylist)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(name), debugstr_w(url), ppPlaylist);
    return E_NOTIMPL;
}

346
static HRESULT WINAPI WMPPlayer4_newMedia(IWMPPlayer4 *iface, BSTR url, IWMPMedia **media)
347 348
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
349 350 351 352

    TRACE("(%p)->(%s %p)\n", This, debugstr_w(url), media);

    return create_media_from_url(url, 0.0, media);
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
}

static HRESULT WINAPI WMPPlayer4_get_enabled(IWMPPlayer4 *iface, VARIANT_BOOL *pbEnabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pbEnabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_enabled(IWMPPlayer4 *iface, VARIANT_BOOL enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%x)\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_fullScreen(IWMPPlayer4 *iface, VARIANT_BOOL *pbFullScreen)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pbFullScreen);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_fullScreen(IWMPPlayer4 *iface, VARIANT_BOOL fullscreen)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%x)\n", This, fullscreen);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_enableContextMenu(IWMPPlayer4 *iface, VARIANT_BOOL *pbEnableContextMenu)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pbEnableContextMenu);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_enableContextMenu(IWMPPlayer4 *iface, VARIANT_BOOL enable)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%x)\n", This, enable);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_uiMode(IWMPPlayer4 *iface, BSTR mode)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(mode));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_uiMode(IWMPPlayer4 *iface, BSTR *pbstrMode)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pbstrMode);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_stretchToFit(IWMPPlayer4 *iface, VARIANT_BOOL *enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_stretchToFit(IWMPPlayer4 *iface, VARIANT_BOOL enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%x)\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_windowlessVideo(IWMPPlayer4 *iface, VARIANT_BOOL *enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_windowlessVideo(IWMPPlayer4 *iface, VARIANT_BOOL enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%x)\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_isRemote(IWMPPlayer4 *iface, VARIANT_BOOL *pvarfIsRemote)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pvarfIsRemote);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_playerApplication(IWMPPlayer4 *iface, IWMPPlayerApplication **ppIWMPPlayerApplication)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppIWMPPlayerApplication);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_openPlayer(IWMPPlayer4 *iface, BSTR url)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(url));
    return E_NOTIMPL;
}

460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
static HRESULT WINAPI WMPPlayer_QueryInterface(IWMPPlayer *iface, REFIID riid, void **ppv)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_QueryInterface(&This->IWMPPlayer4_iface, riid, ppv);
}

static ULONG WINAPI WMPPlayer_AddRef(IWMPPlayer *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_AddRef(&This->IWMPPlayer4_iface);
}

static ULONG WINAPI WMPPlayer_Release(IWMPPlayer *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_Release(&This->IWMPPlayer4_iface);
}

static HRESULT WINAPI WMPPlayer_GetTypeInfoCount(IWMPPlayer *iface, UINT *pctinfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_GetTypeInfoCount(&This->IWMPPlayer4_iface, pctinfo);
}

static HRESULT WINAPI WMPPlayer_GetTypeInfo(IWMPPlayer *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);

    return WMPPlayer4_GetTypeInfo(&This->IWMPPlayer4_iface, iTInfo,
        lcid, ppTInfo);
}

static HRESULT WINAPI WMPPlayer_GetIDsOfNames(IWMPPlayer *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_GetIDsOfNames(&This->IWMPPlayer4_iface, riid,
        rgszNames, cNames, lcid, rgDispId);
}

static HRESULT WINAPI WMPPlayer_Invoke(IWMPPlayer *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_Invoke(&This->IWMPPlayer4_iface, dispIdMember,
        riid, lcid, wFlags, pDispParams, pVarResult,
        pExcepInfo, puArgErr);
}

static HRESULT WINAPI WMPPlayer_close(IWMPPlayer *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_close(&This->IWMPPlayer4_iface);
}

static HRESULT WINAPI WMPPlayer_get_URL(IWMPPlayer *iface, BSTR *pbstrURL)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_URL(&This->IWMPPlayer4_iface, pbstrURL);
}

static HRESULT WINAPI WMPPlayer_put_URL(IWMPPlayer *iface, BSTR url)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_URL(&This->IWMPPlayer4_iface, url);
}

static HRESULT WINAPI WMPPlayer_get_openState(IWMPPlayer *iface, WMPOpenState *pwmpos)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_openState(&This->IWMPPlayer4_iface, pwmpos);
}

static HRESULT WINAPI WMPPlayer_get_playState(IWMPPlayer *iface, WMPPlayState *pwmpps)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_playState(&This->IWMPPlayer4_iface, pwmpps);
}

static HRESULT WINAPI WMPPlayer_get_controls(IWMPPlayer *iface, IWMPControls **ppControl)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_controls(&This->IWMPPlayer4_iface, ppControl);
}

static HRESULT WINAPI WMPPlayer_get_settings(IWMPPlayer *iface, IWMPSettings **ppSettings)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_settings(&This->IWMPPlayer4_iface, ppSettings);
}

static HRESULT WINAPI WMPPlayer_get_currentMedia(IWMPPlayer *iface, IWMPMedia **ppMedia)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_currentMedia(&This->IWMPPlayer4_iface, ppMedia);
}

static HRESULT WINAPI WMPPlayer_put_currentMedia(IWMPPlayer *iface, IWMPMedia *pMedia)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_currentMedia(&This->IWMPPlayer4_iface, pMedia);
}

static HRESULT WINAPI WMPPlayer_get_mediaCollection(IWMPPlayer *iface, IWMPMediaCollection **ppMediaCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_mediaCollection(&This->IWMPPlayer4_iface, ppMediaCollection);
}

static HRESULT WINAPI WMPPlayer_get_playlistCollection(IWMPPlayer *iface, IWMPPlaylistCollection **ppPlaylistCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_playlistCollection(&This->IWMPPlayer4_iface, ppPlaylistCollection);
}

static HRESULT WINAPI WMPPlayer_get_versionInfo(IWMPPlayer *iface, BSTR *version)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_versionInfo(&This->IWMPPlayer4_iface, version);
}

static HRESULT WINAPI WMPPlayer_launchURL(IWMPPlayer *iface, BSTR url)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_launchURL(&This->IWMPPlayer4_iface, url);
}

static HRESULT WINAPI WMPPlayer_get_network(IWMPPlayer *iface, IWMPNetwork **ppQNI)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_network(&This->IWMPPlayer4_iface, ppQNI);
}

static HRESULT WINAPI WMPPlayer_get_currentPlaylist(IWMPPlayer *iface, IWMPPlaylist **ppPL)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_currentPlaylist(&This->IWMPPlayer4_iface, ppPL);
}

static HRESULT WINAPI WMPPlayer_put_currentPlaylist(IWMPPlayer *iface, IWMPPlaylist *pPL)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_currentPlaylist(&This->IWMPPlayer4_iface, pPL);
}

static HRESULT WINAPI WMPPlayer_get_cdromCollection(IWMPPlayer *iface, IWMPCdromCollection **ppCdromCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_cdromCollection(&This->IWMPPlayer4_iface, ppCdromCollection);
}

static HRESULT WINAPI WMPPlayer_get_closedCaption(IWMPPlayer *iface, IWMPClosedCaption **ppClosedCaption)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_closedCaption(&This->IWMPPlayer4_iface, ppClosedCaption);
}

static HRESULT WINAPI WMPPlayer_get_isOnline(IWMPPlayer *iface, VARIANT_BOOL *pfOnline)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_isOnline(&This->IWMPPlayer4_iface, pfOnline);
}

static HRESULT WINAPI WMPPlayer_get_Error(IWMPPlayer *iface, IWMPError **ppError)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_Error(&This->IWMPPlayer4_iface, ppError);
}

static HRESULT WINAPI WMPPlayer_get_Status(IWMPPlayer *iface, BSTR *pbstrStatus)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_Status(&This->IWMPPlayer4_iface, pbstrStatus);
}

static HRESULT WINAPI WMPPlayer_get_enabled(IWMPPlayer *iface, VARIANT_BOOL *pbEnabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_enabled(&This->IWMPPlayer4_iface, pbEnabled);
}

static HRESULT WINAPI WMPPlayer_put_enabled(IWMPPlayer *iface, VARIANT_BOOL enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_enabled(&This->IWMPPlayer4_iface, enabled);
}

static HRESULT WINAPI WMPPlayer_get_fullScreen(IWMPPlayer *iface, VARIANT_BOOL *pbFullScreen)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_fullScreen(&This->IWMPPlayer4_iface, pbFullScreen);
}

static HRESULT WINAPI WMPPlayer_put_fullScreen(IWMPPlayer *iface, VARIANT_BOOL fullscreen)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_fullScreen(&This->IWMPPlayer4_iface, fullscreen);
}

static HRESULT WINAPI WMPPlayer_get_enableContextMenu(IWMPPlayer *iface, VARIANT_BOOL *pbEnableContextMenu)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_enableContextMenu(&This->IWMPPlayer4_iface, pbEnableContextMenu);
}

static HRESULT WINAPI WMPPlayer_put_enableContextMenu(IWMPPlayer *iface, VARIANT_BOOL enable)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_enableContextMenu(&This->IWMPPlayer4_iface, enable);
}

static HRESULT WINAPI WMPPlayer_put_uiMode(IWMPPlayer *iface, BSTR mode)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_uiMode(&This->IWMPPlayer4_iface, mode);
}

static HRESULT WINAPI WMPPlayer_get_uiMode(IWMPPlayer *iface, BSTR *pbstrMode)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_uiMode(&This->IWMPPlayer4_iface, pbstrMode);
}

static IWMPPlayerVtbl WMPPlayerVtbl = {
    WMPPlayer_QueryInterface,
    WMPPlayer_AddRef,
    WMPPlayer_Release,
    WMPPlayer_GetTypeInfoCount,
    WMPPlayer_GetTypeInfo,
    WMPPlayer_GetIDsOfNames,
    WMPPlayer_Invoke,
    WMPPlayer_close,
    WMPPlayer_get_URL,
    WMPPlayer_put_URL,
    WMPPlayer_get_openState,
    WMPPlayer_get_playState,
    WMPPlayer_get_controls,
    WMPPlayer_get_settings,
    WMPPlayer_get_currentMedia,
    WMPPlayer_put_currentMedia,
    WMPPlayer_get_mediaCollection,
    WMPPlayer_get_playlistCollection,
    WMPPlayer_get_versionInfo,
    WMPPlayer_launchURL,
    WMPPlayer_get_network,
    WMPPlayer_get_currentPlaylist,
    WMPPlayer_put_currentPlaylist,
    WMPPlayer_get_cdromCollection,
    WMPPlayer_get_closedCaption,
    WMPPlayer_get_isOnline,
    WMPPlayer_get_Error,
    WMPPlayer_get_Status,
    WMPPlayer_get_enabled,
    WMPPlayer_put_enabled,
    WMPPlayer_get_fullScreen,
    WMPPlayer_put_fullScreen,
    WMPPlayer_get_enableContextMenu,
    WMPPlayer_put_enableContextMenu,
    WMPPlayer_put_uiMode,
    WMPPlayer_get_uiMode,
};


725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
static IWMPPlayer4Vtbl WMPPlayer4Vtbl = {
    WMPPlayer4_QueryInterface,
    WMPPlayer4_AddRef,
    WMPPlayer4_Release,
    WMPPlayer4_GetTypeInfoCount,
    WMPPlayer4_GetTypeInfo,
    WMPPlayer4_GetIDsOfNames,
    WMPPlayer4_Invoke,
    WMPPlayer4_close,
    WMPPlayer4_get_URL,
    WMPPlayer4_put_URL,
    WMPPlayer4_get_openState,
    WMPPlayer4_get_playState,
    WMPPlayer4_get_controls,
    WMPPlayer4_get_settings,
    WMPPlayer4_get_currentMedia,
    WMPPlayer4_put_currentMedia,
    WMPPlayer4_get_mediaCollection,
    WMPPlayer4_get_playlistCollection,
    WMPPlayer4_get_versionInfo,
    WMPPlayer4_launchURL,
    WMPPlayer4_get_network,
    WMPPlayer4_get_currentPlaylist,
    WMPPlayer4_put_currentPlaylist,
    WMPPlayer4_get_cdromCollection,
    WMPPlayer4_get_closedCaption,
    WMPPlayer4_get_isOnline,
    WMPPlayer4_get_Error,
    WMPPlayer4_get_Status,
    WMPPlayer4_get_dvd,
    WMPPlayer4_newPlaylist,
    WMPPlayer4_newMedia,
    WMPPlayer4_get_enabled,
    WMPPlayer4_put_enabled,
    WMPPlayer4_get_fullScreen,
    WMPPlayer4_put_fullScreen,
    WMPPlayer4_get_enableContextMenu,
    WMPPlayer4_put_enableContextMenu,
    WMPPlayer4_put_uiMode,
    WMPPlayer4_get_uiMode,
    WMPPlayer4_get_stretchToFit,
    WMPPlayer4_put_stretchToFit,
    WMPPlayer4_get_windowlessVideo,
    WMPPlayer4_put_windowlessVideo,
    WMPPlayer4_get_isRemote,
    WMPPlayer4_get_playerApplication,
    WMPPlayer4_openPlayer
};

774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
static inline WindowsMediaPlayer *impl_from_IWMPSettings(IWMPSettings *iface)
{
    return CONTAINING_RECORD(iface, WindowsMediaPlayer, IWMPSettings_iface);
}

static HRESULT WINAPI WMPSettings_QueryInterface(IWMPSettings *iface, REFIID riid, void **ppv)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    return IOleObject_QueryInterface(&This->IOleObject_iface, riid, ppv);
}

static ULONG WINAPI WMPSettings_AddRef(IWMPSettings *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    return IOleObject_AddRef(&This->IOleObject_iface);
}

static ULONG WINAPI WMPSettings_Release(IWMPSettings *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    return IOleObject_Release(&This->IOleObject_iface);
}

static HRESULT WINAPI WMPSettings_GetTypeInfoCount(IWMPSettings *iface, UINT *pctinfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_GetTypeInfo(IWMPSettings *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_GetIDsOfNames(IWMPSettings *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_Invoke(IWMPSettings *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_isAvailable(IWMPSettings *iface, BSTR item, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(item), p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_autoStart(IWMPSettings *iface, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
840 841 842 843 844
    TRACE("(%p)->(%p)\n", This, p);
    if (!p)
        return E_POINTER;
    *p = This->auto_start;
    return S_OK;
845 846 847 848 849
}

static HRESULT WINAPI WMPSettings_put_autoStart(IWMPSettings *iface, VARIANT_BOOL v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
850 851 852
    TRACE("(%p)->(%x)\n", This, v);
    This->auto_start = v;
    return S_OK;
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
}

static HRESULT WINAPI WMPSettings_get_baseURL(IWMPSettings *iface, BSTR *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_baseURL(IWMPSettings *iface, BSTR v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_defaultFrame(IWMPSettings *iface, BSTR *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_defaultFrame(IWMPSettings *iface, BSTR v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_invokeURLs(IWMPSettings *iface, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
886 887 888 889 890 891 892

    TRACE("(%p)->(%p)\n", This, p);

    if (!p)
        return E_POINTER;
    *p = This->invoke_urls;
    return S_OK;
893 894 895 896 897
}

static HRESULT WINAPI WMPSettings_put_invokeURLs(IWMPSettings *iface, VARIANT_BOOL v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
898
    /* Leaving as FIXME as we don't currently use this */
899
    FIXME("(%p)->(%x)\n", This, v);
900 901
    This->invoke_urls = v;
    return S_OK;
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
}

static HRESULT WINAPI WMPSettings_get_mute(IWMPSettings *iface, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_mute(IWMPSettings *iface, VARIANT_BOOL v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%x)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_playCount(IWMPSettings *iface, LONG *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_playCount(IWMPSettings *iface, LONG v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%d)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_rate(IWMPSettings *iface, double *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_rate(IWMPSettings *iface, double v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%lf)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_balance(IWMPSettings *iface, LONG *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_balance(IWMPSettings *iface, LONG v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%d)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_volume(IWMPSettings *iface, LONG *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
963 964 965 966 967
    TRACE("(%p)->(%p)\n", This, p);
    if (!p)
        return E_POINTER;
    *p = This->volume;
    return S_OK;
968 969 970 971
}

static HRESULT WINAPI WMPSettings_put_volume(IWMPSettings *iface, LONG v)
{
972
    HRESULT hres;
973
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
974 975 976 977 978 979 980 981 982 983
    TRACE("(%p)->(%d)\n", This, v);
    This->volume = v;
    if (!This->filter_graph) {
        hres = S_OK;
    } else {
        /* IBasicAudio -   [-10000, 0], wmp - [0, 100] */
        v = 10000 * v / 100 - 10000;
        hres = IBasicAudio_put_Volume(This->basic_audio, v);
    }
    return hres;
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
}

static HRESULT WINAPI WMPSettings_getMode(IWMPSettings *iface, BSTR mode, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(mode), p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_setMode(IWMPSettings *iface, BSTR mode, VARIANT_BOOL v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s %x)\n", This, debugstr_w(mode), v);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_enableErrorDialogs(IWMPSettings *iface, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
1003 1004 1005 1006 1007 1008 1009

    TRACE("(%p)->(%p)\n", This, p);

    if (!p)
        return E_POINTER;
    *p = This->enable_error_dialogs;
    return S_OK;
1010 1011 1012 1013 1014
}

static HRESULT WINAPI WMPSettings_put_enableErrorDialogs(IWMPSettings *iface, VARIANT_BOOL v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
1015
    /* Leaving as FIXME as we don't currently use this */
1016
    FIXME("(%p)->(%x)\n", This, v);
1017 1018
    This->enable_error_dialogs = v;
    return S_OK;
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
}

static const IWMPSettingsVtbl WMPSettingsVtbl = {
    WMPSettings_QueryInterface,
    WMPSettings_AddRef,
    WMPSettings_Release,
    WMPSettings_GetTypeInfoCount,
    WMPSettings_GetTypeInfo,
    WMPSettings_GetIDsOfNames,
    WMPSettings_Invoke,
    WMPSettings_get_isAvailable,
    WMPSettings_get_autoStart,
    WMPSettings_put_autoStart,
    WMPSettings_get_baseURL,
    WMPSettings_put_baseURL,
    WMPSettings_get_defaultFrame,
    WMPSettings_put_defaultFrame,
    WMPSettings_get_invokeURLs,
    WMPSettings_put_invokeURLs,
    WMPSettings_get_mute,
    WMPSettings_put_mute,
    WMPSettings_get_playCount,
    WMPSettings_put_playCount,
    WMPSettings_get_rate,
    WMPSettings_put_rate,
    WMPSettings_get_balance,
    WMPSettings_put_balance,
    WMPSettings_get_volume,
    WMPSettings_put_volume,
    WMPSettings_getMode,
    WMPSettings_setMode,
    WMPSettings_get_enableErrorDialogs,
    WMPSettings_put_enableErrorDialogs
};

1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
static HRESULT WINAPI WMPNetwork_QueryInterface(IWMPNetwork *iface, REFIID riid, void **ppv)
{
    if(IsEqualGUID(riid, &IID_IDispatch)) {
        *ppv = iface;
    }else if(IsEqualGUID(riid, &IID_IWMPNetwork)) {
        *ppv = iface;
    }else {
        WARN("Unsupported interface (%s)\n", wine_dbgstr_guid(riid));
        *ppv = NULL;
        return E_NOINTERFACE;
    }

    IUnknown_AddRef((IUnknown*)*ppv);
    return S_OK;
}

static ULONG WINAPI WMPNetwork_AddRef(IWMPNetwork *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    return IOleObject_AddRef(&This->IOleObject_iface);
}

static ULONG WINAPI WMPNetwork_Release(IWMPNetwork *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    return IOleObject_Release(&This->IOleObject_iface);
}

static HRESULT WINAPI WMPNetwork_GetTypeInfoCount(IWMPNetwork *iface, UINT *pctinfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_GetTypeInfo(IWMPNetwork *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_GetIDsOfNames(IWMPNetwork *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_Invoke(IWMPNetwork *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_bandWidth(IWMPNetwork *iface, LONG *plBandwidth)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plBandwidth);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_recoveredPackets(IWMPNetwork *iface, LONG *plRecoveredPackets)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plRecoveredPackets);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_sourceProtocol(IWMPNetwork *iface, BSTR *pbstrSourceProtocol)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, pbstrSourceProtocol);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_receivedPackets(IWMPNetwork *iface, LONG *plReceivedPackets)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plReceivedPackets);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_lostPackets(IWMPNetwork *iface, LONG *plLostPackets)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plLostPackets);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_receptionQuality(IWMPNetwork *iface, LONG *plReceptionQuality)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plReceptionQuality);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_bufferingCount(IWMPNetwork *iface, LONG *plBufferingCount)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plBufferingCount);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_bufferingProgress(IWMPNetwork *iface, LONG *plBufferingProgress)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177
    TRACE("(%p)->(%p)\n", This, plBufferingProgress);
    if (!This->filter_graph) {
        return S_FALSE;
    }
    /* Ideally we would use IAMOpenProgress for URL reader but we don't have it in wine (yet)
     * For file sources FileAsyncReader->Length should work
     * */
    FIXME("stub: Returning buffering progress 100\n");
    *plBufferingProgress = 100;

    return S_OK;
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
}

static HRESULT WINAPI WMPNetwork_get_bufferingTime(IWMPNetwork *iface, LONG *plBufferingTime)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plBufferingTime);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_put_bufferingTime(IWMPNetwork *iface, LONG lBufferingTime)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%d)\n", This, lBufferingTime);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_frameRate(IWMPNetwork *iface, LONG *plFrameRate)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plFrameRate);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_maxBitRate(IWMPNetwork *iface, LONG *plBitRate)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plBitRate);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_bitRate(IWMPNetwork *iface, LONG *plBitRate)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plBitRate);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_getProxySettings(IWMPNetwork *iface, BSTR bstrProtocol, LONG *plProxySetting)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrProtocol), plProxySetting);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_setProxySettings(IWMPNetwork *iface, BSTR bstrProtocol, LONG lProxySetting)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %d)\n", This, debugstr_w(bstrProtocol), lProxySetting);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_getProxyName(IWMPNetwork *iface, BSTR bstrProtocol, BSTR *pbstrProxyName)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrProtocol), pbstrProxyName);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_setProxyName(IWMPNetwork *iface, BSTR bstrProtocol, BSTR bstrProxyName)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %s)\n", This, debugstr_w(bstrProtocol), debugstr_w(bstrProxyName));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_getProxyPort(IWMPNetwork *iface, BSTR bstrProtocol, LONG *plProxyPort)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrProtocol), plProxyPort);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_setProxyPort(IWMPNetwork *iface, BSTR bstrProtocol, LONG lProxyPort)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %d)\n", This, debugstr_w(bstrProtocol), lProxyPort);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_getProxyExceptionList(IWMPNetwork *iface, BSTR bstrProtocol, BSTR *pbstrExceptionList)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrProtocol), pbstrExceptionList);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_setProxyExceptionList(IWMPNetwork *iface, BSTR bstrProtocol, BSTR bstrExceptionList)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %s)\n", This, debugstr_w(bstrProtocol), debugstr_w(bstrExceptionList));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_getProxyBypassForLocal(IWMPNetwork *iface, BSTR bstrProtocol, VARIANT_BOOL *pfBypassForLocal)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrProtocol), pfBypassForLocal);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_setProxyBypassForLocal(IWMPNetwork *iface, BSTR bstrProtocol, VARIANT_BOOL fBypassForLocal)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %d)\n", This, debugstr_w(bstrProtocol), fBypassForLocal);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_maxBandwidth(IWMPNetwork *iface, LONG *plMaxBandwidth)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plMaxBandwidth);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_put_maxBandwidth(IWMPNetwork *iface, LONG lMaxBandwidth)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%d)\n", This, lMaxBandwidth);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_downloadProgress(IWMPNetwork *iface, LONG *plDownloadProgress)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
    TRACE("(%p)->(%p)\n", This, plDownloadProgress);
    if (!This->filter_graph) {
        return S_FALSE;
    }
    /* Ideally we would use IAMOpenProgress for URL reader but we don't have it in wine (yet)
     * For file sources FileAsyncReader->Length could work or it should just be
     * 100
     * */
    FIXME("stub: Returning download progress 100\n");
    *plDownloadProgress = 100;

    return S_OK;
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
}

static HRESULT WINAPI WMPNetwork_get_encodedFrameRate(IWMPNetwork *iface, LONG *plFrameRate)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plFrameRate);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_framesSkipped(IWMPNetwork *iface, LONG *plFrames)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plFrames);
    return E_NOTIMPL;
}

static const IWMPNetworkVtbl WMPNetworkVtbl = {
    WMPNetwork_QueryInterface,
    WMPNetwork_AddRef,
    WMPNetwork_Release,
    WMPNetwork_GetTypeInfoCount,
    WMPNetwork_GetTypeInfo,
    WMPNetwork_GetIDsOfNames,
    WMPNetwork_Invoke,
    WMPNetwork_get_bandWidth,
    WMPNetwork_get_recoveredPackets,
    WMPNetwork_get_sourceProtocol,
    WMPNetwork_get_receivedPackets,
    WMPNetwork_get_lostPackets,
    WMPNetwork_get_receptionQuality,
    WMPNetwork_get_bufferingCount,
    WMPNetwork_get_bufferingProgress,
    WMPNetwork_get_bufferingTime,
    WMPNetwork_put_bufferingTime,
    WMPNetwork_get_frameRate,
    WMPNetwork_get_maxBitRate,
    WMPNetwork_get_bitRate,
    WMPNetwork_getProxySettings,
    WMPNetwork_setProxySettings,
    WMPNetwork_getProxyName,
    WMPNetwork_setProxyName,
    WMPNetwork_getProxyPort,
    WMPNetwork_setProxyPort,
    WMPNetwork_getProxyExceptionList,
    WMPNetwork_setProxyExceptionList,
    WMPNetwork_getProxyBypassForLocal,
    WMPNetwork_setProxyBypassForLocal,
    WMPNetwork_get_maxBandwidth,
    WMPNetwork_put_maxBandwidth,
    WMPNetwork_get_downloadProgress,
    WMPNetwork_get_encodedFrameRate,
    WMPNetwork_get_framesSkipped,
};

1368
static HRESULT WINAPI WMPControls_QueryInterface(IWMPControls *iface, REFIID riid, void **ppv)
1369
{
1370 1371 1372
    if(IsEqualGUID(riid, &IID_IUnknown)) {
        *ppv = iface;
    }else if(IsEqualGUID(riid, &IID_IDispatch)) {
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433
        *ppv = iface;
    }else if(IsEqualGUID(riid, &IID_IWMPControls)) {
        *ppv = iface;
    }else {
        WARN("Unsupported interface (%s)\n", wine_dbgstr_guid(riid));
        *ppv = NULL;
        return E_NOINTERFACE;
    }

    IUnknown_AddRef((IUnknown*)*ppv);
    return S_OK;
}

static ULONG WINAPI WMPControls_AddRef(IWMPControls *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    return IOleObject_AddRef(&This->IOleObject_iface);
}

static ULONG WINAPI WMPControls_Release(IWMPControls *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    return IOleObject_Release(&This->IOleObject_iface);
}

static HRESULT WINAPI WMPControls_GetTypeInfoCount(IWMPControls *iface, UINT *pctinfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPControls_GetTypeInfo(IWMPControls *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPControls_GetIDsOfNames(IWMPControls *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPControls_Invoke(IWMPControls *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPControls_get_isAvailable(IWMPControls *iface, BSTR bstrItem, VARIANT_BOOL *pIsAvailable)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448
    static const WCHAR currentPosition[] = {'c','u','r','r','e','n','t','P','o','s','i','t','i','o','n',0};
    TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrItem), pIsAvailable);
    if (!This->filter_graph) {
        *pIsAvailable = VARIANT_FALSE;
    } else if (strcmpW(currentPosition, bstrItem) == 0) {
        DWORD capabilities;
        IMediaSeeking_GetCapabilities(This->media_seeking, &capabilities);
        *pIsAvailable = (capabilities & AM_SEEKING_CanSeekAbsolute) ?
            VARIANT_TRUE : VARIANT_FALSE;
    } else {
        FIXME("%s not implemented\n", debugstr_w(bstrItem));
        return E_NOTIMPL;
    }

    return S_OK;
1449 1450
}

1451
static HRESULT WINAPI WMPControls_play(IWMPControls *iface)
1452
{
1453
    HRESULT hres = S_OK;
1454
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
1455 1456 1457

    TRACE("(%p)\n", This);

1458
    if (!This->media) {
1459 1460 1461 1462 1463 1464 1465 1466 1467
        return NS_S_WMPCORE_COMMAND_NOT_AVAILABLE;
    }

    if (!This->filter_graph) {
        hres = CoCreateInstance(&CLSID_FilterGraph,
                NULL,
                CLSCTX_INPROC_SERVER,
                &IID_IGraphBuilder,
                (void **)&This->filter_graph);
1468 1469
        update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposOpeningUnknownURL);

1470
        if (SUCCEEDED(hres))
1471
            hres = IGraphBuilder_RenderFile(This->filter_graph, This->media->url, NULL);
1472 1473
        if (SUCCEEDED(hres))
            update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposMediaOpen);
1474 1475 1476
        if (SUCCEEDED(hres))
            hres = IGraphBuilder_QueryInterface(This->filter_graph, &IID_IMediaControl,
                    (void**)&This->media_control);
1477
        if (SUCCEEDED(hres))
1478 1479 1480 1481
            hres = IGraphBuilder_QueryInterface(This->filter_graph, &IID_IMediaSeeking,
                    (void**)&This->media_seeking);
        if (SUCCEEDED(hres))
            hres = IMediaSeeking_SetTimeFormat(This->media_seeking, &TIME_FORMAT_MEDIA_TIME);
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
        if (SUCCEEDED(hres))
            hres = IGraphBuilder_QueryInterface(This->filter_graph, &IID_IMediaEvent,
                    (void**)&This->media_event);
        if (SUCCEEDED(hres))
        {
            IMediaEventEx *media_event_ex = NULL;
            hres = IGraphBuilder_QueryInterface(This->filter_graph, &IID_IMediaEventEx,
                    (void**)&media_event_ex);
            if (SUCCEEDED(hres)) {
                hres = IMediaEventEx_SetNotifyWindow(media_event_ex, (OAHWND)This->msg_window,
                        WM_WMPEVENT, (LONG_PTR)This);
                IMediaEventEx_Release(media_event_ex);
            }
        }
1496 1497 1498 1499
        if (SUCCEEDED(hres))
            hres = IGraphBuilder_QueryInterface(This->filter_graph, &IID_IBasicAudio, (void**)&This->basic_audio);
        if (SUCCEEDED(hres))
            hres = IWMPSettings_put_volume(&This->IWMPSettings_iface, This->volume);
1500 1501
    }

1502 1503
    update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsTransitioning);

1504 1505 1506 1507 1508 1509
    if (SUCCEEDED(hres))
        hres = IMediaControl_Run(This->media_control);

    if (hres == S_FALSE) {
        hres = S_OK; /* S_FALSE will mean that graph is transitioning and that is fine */
    }
1510 1511

    if (SUCCEEDED(hres)) {
1512
        LONGLONG duration;
1513
        update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsPlaying);
1514
        if (SUCCEEDED(IMediaSeeking_GetDuration(This->media_seeking, &duration)))
1515
            This->media->duration = (DOUBLE)duration / 10000000.0f;
1516 1517 1518 1519
    } else {
        update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsUndefined);
    }

1520
    return hres;
1521 1522
}

1523
static HRESULT WINAPI WMPControls_stop(IWMPControls *iface)
1524
{
1525
    HRESULT hres = S_OK;
1526
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
1527 1528 1529 1530 1531 1532 1533 1534
    TRACE("(%p)\n", This);
    if (!This->filter_graph) {
        return NS_S_WMPCORE_COMMAND_NOT_AVAILABLE;
    }
    if (This->media_control) {
        hres = IMediaControl_Stop(This->media_control);
        IMediaControl_Release(This->media_control);
    }
1535 1536 1537
    if (This->media_event) {
        IMediaEvent_Release(This->media_event);
    }
1538 1539 1540
    if (This->media_seeking) {
        IMediaSeeking_Release(This->media_seeking);
    }
1541 1542 1543
    if (This->basic_audio) {
        IBasicAudio_Release(This->basic_audio);
    }
1544 1545 1546
    IGraphBuilder_Release(This->filter_graph);
    This->filter_graph = NULL;
    This->media_control = NULL;
1547
    This->media_event = NULL;
1548
    This->media_seeking = NULL;
1549
    This->basic_audio = NULL;
1550

1551 1552
    update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposPlaylistOpenNoMedia);
    update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsStopped);
1553
    return hres;
1554 1555
}

1556
static HRESULT WINAPI WMPControls_pause(IWMPControls *iface)
1557 1558 1559 1560 1561 1562
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

1563
static HRESULT WINAPI WMPControls_fastForward(IWMPControls *iface)
1564 1565 1566 1567 1568 1569
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

1570
static HRESULT WINAPI WMPControls_fastReverse(IWMPControls *iface)
1571 1572 1573 1574 1575 1576
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

1577
static HRESULT WINAPI WMPControls_get_currentPosition(IWMPControls *iface, DOUBLE *pdCurrentPosition)
1578 1579
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590
    HRESULT hres;
    LONGLONG currentPosition;

    TRACE("(%p)->(%p)\n", This, pdCurrentPosition);
    if (!This->media_seeking)
        return S_FALSE;

    hres = IMediaSeeking_GetCurrentPosition(This->media_seeking, &currentPosition);
    *pdCurrentPosition = (DOUBLE) currentPosition / 10000000.0f;
    TRACE("hres: %d, pos: %f\n", hres, *pdCurrentPosition);
    return hres;
1591 1592
}

1593
static HRESULT WINAPI WMPControls_put_currentPosition(IWMPControls *iface, DOUBLE dCurrentPosition)
1594
{
1595 1596
    LONGLONG Current;
    HRESULT hres;
1597
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
1598 1599 1600 1601 1602 1603 1604 1605 1606
    TRACE("(%p)->(%f)\n", This, dCurrentPosition);
    if (!This->media_seeking)
        return S_FALSE;

    Current = 10000000 * dCurrentPosition;
    hres = IMediaSeeking_SetPositions(This->media_seeking, &Current,
            AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);

    return hres;
1607 1608
}

1609
static HRESULT WINAPI WMPControls_get_currentPositionString(IWMPControls *iface, BSTR *pbstrCurrentPosition)
1610 1611 1612 1613 1614 1615
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, pbstrCurrentPosition);
    return E_NOTIMPL;
}

1616
static HRESULT WINAPI WMPControls_next(IWMPControls *iface)
1617 1618 1619 1620 1621 1622
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

1623
static HRESULT WINAPI WMPControls_previous(IWMPControls *iface)
1624 1625 1626 1627 1628 1629
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

1630
static HRESULT WINAPI WMPControls_get_currentItem(IWMPControls *iface, IWMPMedia **ppIWMPMedia)
1631 1632 1633 1634 1635 1636
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, ppIWMPMedia);
    return E_NOTIMPL;
}

1637
static HRESULT WINAPI WMPControls_put_currentItem(IWMPControls *iface, IWMPMedia *pIWMPMedia)
1638 1639 1640 1641 1642 1643
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, pIWMPMedia);
    return E_NOTIMPL;
}

1644
static HRESULT WINAPI WMPControls_get_currentMarker(IWMPControls *iface, LONG *plMarker)
1645 1646 1647 1648 1649 1650
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, plMarker);
    return E_NOTIMPL;
}

1651
static HRESULT WINAPI WMPControls_put_currentMarker(IWMPControls *iface, LONG lMarker)
1652 1653 1654 1655 1656 1657
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%d)\n", This, lMarker);
    return E_NOTIMPL;
}

1658
static HRESULT WINAPI WMPControls_playItem(IWMPControls *iface, IWMPMedia *pIWMPMedia)
1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, pIWMPMedia);
    return E_NOTIMPL;
}

static const IWMPControlsVtbl WMPControlsVtbl = {
    WMPControls_QueryInterface,
    WMPControls_AddRef,
    WMPControls_Release,
    WMPControls_GetTypeInfoCount,
    WMPControls_GetTypeInfo,
    WMPControls_GetIDsOfNames,
    WMPControls_Invoke,
    WMPControls_get_isAvailable,
    WMPControls_play,
    WMPControls_stop,
    WMPControls_pause,
    WMPControls_fastForward,
    WMPControls_fastReverse,
    WMPControls_get_currentPosition,
    WMPControls_put_currentPosition,
    WMPControls_get_currentPositionString,
    WMPControls_next,
    WMPControls_previous,
    WMPControls_get_currentItem,
    WMPControls_put_currentItem,
    WMPControls_get_currentMarker,
    WMPControls_put_currentMarker,
    WMPControls_playItem,
};

1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778
static HRESULT WINAPI WMPMedia_QueryInterface(IWMPMedia *iface, REFIID riid, void **ppv)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    TRACE("(%p)\n", This);
    if(IsEqualGUID(&IID_IUnknown, riid)) {
        TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
        *ppv = &This->IWMPMedia_iface;
    }else if(IsEqualGUID(&IID_IDispatch, riid)) {
        TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
        *ppv = &This->IWMPMedia_iface;
    }else if(IsEqualGUID(&IID_IWMPMedia, riid)) {
        TRACE("(%p)->(IID_IWMPMedia %p)\n", This, ppv);
        *ppv = &This->IWMPMedia_iface;
    }else {
        WARN("Unsupported interface %s\n", debugstr_guid(riid));
        *ppv = NULL;
        return E_NOINTERFACE;
    }

    IUnknown_AddRef((IUnknown*)*ppv);
    return S_OK;
}

static ULONG WINAPI WMPMedia_AddRef(IWMPMedia *iface)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    LONG ref = InterlockedIncrement(&This->ref);

    TRACE("(%p) ref=%d\n", This, ref);

    return ref;
}

static ULONG WINAPI WMPMedia_Release(IWMPMedia *iface)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    LONG ref = InterlockedDecrement(&This->ref);

    TRACE("(%p) ref=%d\n", This, ref);

    if(!ref) {
        heap_free(This->url);
        heap_free(This);
    }

    return ref;
}

static HRESULT WINAPI WMPMedia_GetTypeInfoCount(IWMPMedia *iface, UINT *pctinfo)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_GetTypeInfo(IWMPMedia *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_GetIDsOfNames(IWMPMedia *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_Invoke(IWMPMedia *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_isIdentical(IWMPMedia *iface, IWMPMedia *other, VARIANT_BOOL *pvBool)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p, %p)\n", This, other, pvBool);
    return E_NOTIMPL;
}

1779
static HRESULT WINAPI WMPMedia_get_sourceURL(IWMPMedia *iface, BSTR *url)
1780 1781
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
1782 1783 1784 1785

    TRACE("(%p)->(%p)\n", This, url);

    return return_bstr(This->url, url);
1786 1787
}

1788
static HRESULT WINAPI WMPMedia_get_name(IWMPMedia *iface, BSTR *name)
1789 1790
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
1791 1792 1793 1794 1795

    FIXME("(%p)->(%p)\n", This, name);

    /* FIXME: this should be a display name */
    return return_bstr(This->url, name);
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841
}

static HRESULT WINAPI WMPMedia_put_name(IWMPMedia *iface, BSTR pbstrName)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(pbstrName));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_imageSourceWidth(IWMPMedia *iface, LONG *pWidth)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, pWidth);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_imageSourceHeight(IWMPMedia *iface, LONG *pHeight)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, pHeight);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_markerCount(IWMPMedia *iface, LONG* pMarkerCount)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, pMarkerCount);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_getMarkerTime(IWMPMedia *iface, LONG MarkerNum, DOUBLE *pMarkerTime)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%d, %p)\n", This, MarkerNum, pMarkerTime);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_getMarkerName(IWMPMedia *iface, LONG MarkerNum, BSTR *pbstrMarkerName)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%d, %p)\n", This, MarkerNum, pbstrMarkerName);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_duration(IWMPMedia *iface, DOUBLE *pDuration)
{
1842 1843
    /* MSDN: If this property is used with a media item other than the one
     * specified in Player.currentMedia, it may not contain a valid value. */
1844
    WMPMedia *This = impl_from_IWMPMedia(iface);
1845 1846 1847
    TRACE("(%p)->(%p)\n", This, pDuration);
    *pDuration = This->duration;
    return S_OK;
1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933
}

static HRESULT WINAPI WMPMedia_get_durationString(IWMPMedia *iface, BSTR *pbstrDuration)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, pbstrDuration);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_attributeCount(IWMPMedia *iface, LONG *plCount)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, plCount);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_getAttributeName(IWMPMedia *iface, LONG lIndex, BSTR *pbstrItemName)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%d, %p)\n", This, lIndex, pbstrItemName);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_getItemInfo(IWMPMedia *iface, BSTR bstrItemName, BSTR *pbstrVal)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrItemName), pbstrVal);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_setItemInfo(IWMPMedia *iface, BSTR bstrItemName, BSTR bstrVal)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%s, %s)\n", This, debugstr_w(bstrItemName), debugstr_w(bstrVal));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_getItemInfoByAtom(IWMPMedia *iface, LONG lAtom, BSTR *pbstrVal)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%d, %p)\n", This, lAtom, pbstrVal);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_isMemberOf(IWMPMedia *iface, IWMPPlaylist *pPlaylist, VARIANT_BOOL *pvarfIsMemberOf)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p, %p)\n", This, pPlaylist, pvarfIsMemberOf);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_isReadOnlyItem(IWMPMedia *iface, BSTR bstrItemName, VARIANT_BOOL *pvarfIsReadOnly)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrItemName), pvarfIsReadOnly);
    return E_NOTIMPL;
}

static const IWMPMediaVtbl WMPMediaVtbl = {
    WMPMedia_QueryInterface,
    WMPMedia_AddRef,
    WMPMedia_Release,
    WMPMedia_GetTypeInfoCount,
    WMPMedia_GetTypeInfo,
    WMPMedia_GetIDsOfNames,
    WMPMedia_Invoke,
    WMPMedia_get_isIdentical,
    WMPMedia_get_sourceURL,
    WMPMedia_get_name,
    WMPMedia_put_name,
    WMPMedia_get_imageSourceWidth,
    WMPMedia_get_imageSourceHeight,
    WMPMedia_get_markerCount,
    WMPMedia_getMarkerTime,
    WMPMedia_getMarkerName,
    WMPMedia_get_duration,
    WMPMedia_get_durationString,
    WMPMedia_get_attributeCount,
    WMPMedia_getAttributeName,
    WMPMedia_getItemInfo,
    WMPMedia_setItemInfo,
    WMPMedia_getItemInfoByAtom,
    WMPMedia_isMemberOf,
    WMPMedia_isReadOnlyItem
};

1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980
static LRESULT WINAPI player_wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    if (msg == WM_WMPEVENT && wParam == 0) {
        WindowsMediaPlayer *wmp = (WindowsMediaPlayer*)lParam;
        LONG event_code;
        LONG_PTR p1, p2;
        HRESULT hr;
        if (wmp->media_event) {
            do {
                hr = IMediaEvent_GetEvent(wmp->media_event, &event_code, &p1, &p2, 0);
                if (SUCCEEDED(hr)) {
                    TRACE("got event_code = 0x%02x\n", event_code);
                    IMediaEvent_FreeEventParams(wmp->media_event, event_code, p1, p2);
                    /* For now we only handle EC_COMPLETE */
                    if (event_code == EC_COMPLETE) {
                        update_state(wmp, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsMediaEnded);
                        update_state(wmp, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsTransitioning);
                        update_state(wmp, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsStopped);
                    }
                }
            } while (hr == S_OK);
        } else {
            FIXME("Got event from quartz when interfaces are already released\n");
        }
    }
    return DefWindowProcW(hwnd, msg, wParam, lParam);
}

static BOOL WINAPI register_player_msg_class(INIT_ONCE *once, void *param, void **context) {
    static WNDCLASSEXW wndclass = {
        sizeof(wndclass), CS_DBLCLKS, player_wnd_proc, 0, 0,
        NULL, NULL, NULL, NULL, NULL,
        WMPmessageW, NULL
    };

    wndclass.hInstance = wmp_instance;
    player_msg_class = RegisterClassExW(&wndclass);
    WM_WMPEVENT= RegisterWindowMessageW(WMPmessageW);
    return TRUE;
}

void unregister_player_msg_class(void) {
    if(player_msg_class)
        UnregisterClassW(MAKEINTRESOURCEW(player_msg_class), wmp_instance);
}

BOOL init_player(WindowsMediaPlayer *wmp)
1981
{
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993
    InitOnceExecuteOnce(&class_init_once, register_player_msg_class, NULL, NULL);
    wmp->msg_window = CreateWindowW( MAKEINTRESOURCEW(player_msg_class), NULL, 0, 0,
            0, 0, 0, HWND_MESSAGE, 0, wmp_instance, wmp );
    if (!wmp->msg_window) {
        ERR("Failed to create message window, GetLastError: %d\n", GetLastError());
        return FALSE;
    }
    if (!WM_WMPEVENT) {
        ERR("Failed to register window message, GetLastError: %d\n", GetLastError());
        return FALSE;
    }

1994
    wmp->IWMPPlayer4_iface.lpVtbl = &WMPPlayer4Vtbl;
1995
    wmp->IWMPPlayer_iface.lpVtbl = &WMPPlayerVtbl;
1996
    wmp->IWMPSettings_iface.lpVtbl = &WMPSettingsVtbl;
1997
    wmp->IWMPControls_iface.lpVtbl = &WMPControlsVtbl;
1998
    wmp->IWMPNetwork_iface.lpVtbl = &WMPNetworkVtbl;
1999 2000 2001

    wmp->invoke_urls = VARIANT_TRUE;
    wmp->auto_start = VARIANT_TRUE;
2002
    wmp->volume = 100;
2003
    return TRUE;
2004
}
2005 2006 2007

void destroy_player(WindowsMediaPlayer *wmp)
{
2008
    IWMPControls_stop(&wmp->IWMPControls_iface);
2009 2010
    if (wmp->media)
        IWMPMedia_Release(&wmp->media->IWMPMedia_iface);
2011
    DestroyWindow(wmp->msg_window);
2012 2013
}

2014 2015 2016 2017 2018 2019 2020
WMPMedia *unsafe_impl_from_IWMPMedia(IWMPMedia *iface)
{
    if (iface->lpVtbl == &WMPMediaVtbl) {
        return CONTAINING_RECORD(iface, WMPMedia, IWMPMedia_iface);
    }
    return NULL;
}
2021

2022
HRESULT create_media_from_url(BSTR url, double duration, IWMPMedia **ppMedia)
2023
{
2024
    WMPMedia *media;
2025

2026 2027
    media = heap_alloc_zero(sizeof(*media));
    if (!media)
2028 2029
        return E_OUTOFMEMORY;

2030
    media->IWMPMedia_iface.lpVtbl = &WMPMediaVtbl;
2031 2032
    media->url = url ? heap_strdupW(url) : heap_strdupW(emptyW);
    media->duration = duration;
2033 2034
    media->ref = 1;

2035 2036 2037 2038 2039 2040 2041
    if (media->url) {
        *ppMedia = &media->IWMPMedia_iface;

        return S_OK;
    }
    IWMPMedia_Release(&media->IWMPMedia_iface);
    return E_OUTOFMEMORY;
2042
}