Note that there are some explanatory texts on larger screens.

plurals
  1. PObasic playback with programmatically created windows media player
    primarykey
    data
    text
    <p>I was trying to <em>"just quickly integrate"</em> the Windows Media Player via COM to play single files from the local file system or http sources - but due to the sparse documentation and online resources to its usage when not embedding into some kind of an Ole container, i couldn't get that supposedly trivial use-case to work.</p> <p>Initialization etc. works fine, but actually playing some file always fails.</p> <p>Example code, starting with initialization (error handling stripped, basically translated from the <a href="http://msdn.microsoft.com/en-us/library/dd562692(VS.85).aspx" rel="nofollow noreferrer">C# example at MSDN</a>, executed on the main thread):</p> <pre><code>CComPtr&lt;IWMPPlayer&gt; player; player.CoCreateInstance(__uuidof(WindowsMediaPlayer), 0, CLSCTX_INPROC_SERVER); CComQIPtr&lt;IWMPCore3&gt; core(player); CComPtr&lt;IWMPControls&gt; controls; core-&gt;get_controls(&amp;controls); CComPtr&lt;IWMPPlaylist&gt; playlist; core-&gt;get_currentPlaylist(&amp;playlist); CComBSTR path("c:\\bar.mp3"); // alternatively http://foo/bar.mp3 </code></pre> <p>The first approach to play something gives <em>"command not available"</em>:</p> <pre><code>core-&gt;put_url(path); // ... waiting after that for WMP to load doesn't make a difference controls-&gt;play(); // returns 0x000D1105 - NS_S_WMPCORE_COMMAND_NOT_AVAILABLE </code></pre> <p>The second approach only produces <code>S_OK</code>s, but nothing is actually played:</p> <pre><code>CComPtr&lt;IWMPMedia&gt; media; core-&gt;newMedia(path, &amp;media); playlist-&gt;appendItem(media); controls-&gt;playItem(media); // returns S_OK, but doesn't play </code></pre> <p>Another thing i noted is that <code>core-&gt;get_playState()</code> always returns <code>wmposMediaOpening</code>, no matter how long i wait.</p> <p>I've stumbled upon one thread that suggests multi-threading might not work properly with WMP and this code runs in a multi-threaded apartment. Might that be the problem?<br> If not, what else could be preventing WMP from playing the files?</p> <p><em>Notable background:</em><br> The WMP instance is created in a DLL with a browser as the host-process.</p> <p><em>Update:</em><br> Trying plain DirectShow, which WMP should be using itself, exhibits a more specific problem - see the <a href="https://stackoverflow.com/questions/1963241/">question for that</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload