简体   繁体   English

如何播放同时下载的mp3?

[英]How to play mp3 that is downloaded at the same time?

I wrote program that downloads mp3 file. 我写了下载mp3文件的程序。 It's works fine. 很好 My next task is to play the file that is downloaded at the same time using DirectShow. 我的下一个任务是使用DirectShow播放同时下载的文件。 On MSDN website I found and copied this code: 在MSDN网站上,我找到并复制了以下代码:

HRESULT hr = CoInitialize(NULL);
    if (FAILED(hr))
    {
        //
    }
IGraphBuilder *pGraph;
hr = CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);

IMediaControl *pControl;
IMediaEvent   *pEvent;
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

hr = pGraph->RenderFile(L"C:\\Test.mp3", NULL);

hr = pControl->Run();

long evCode = 0;
pEvent->WaitForCompletion(INFINITE, &evCode);

pControl->Release();
pEvent->Release();
pGraph->Release();
CoUninitialize();

And the problem is that program can not play this file. 问题是程序无法播放此文件。 For writing data I open the file using the following code: 为了写入数据,我使用以下代码打开文件:

TFileStream *MyFile = new TFileStream(path,fmOpenWrite | fmShareDenyNone);

that allows other applications to read the file. 允许其他应用程序读取文件。 I also used the WINAPI function to open and write the file, but result is the same. 我还使用WINAPI函数打开和写入文件,但是结果是相同的。

Where I made the mistake? 我在哪里弄错了?

Please help me - what are the ways to play the file that is downloaded at this time? 请帮助我-播放当前下载文件的方式是什么?

Standard DirectShow playback assumes the data is taken from a file: File Source (Async) Filter or WM ASF Reader Filter take file path and stream data further. 标准DirectShow播放假定数据取自文件: File Source (Async) FilterWM ASF Reader Filter将获取文件路径并进一步传输数据。 Since your download is still in progress, you cannot provide a complete file and these components cannot play data, because of incompleteness and/or because of sharing violation. 由于下载仍在进行中,由于不完整和/或由于共享冲突,您无法提供完整的文件,并且这些组件也无法播放数据。

To make the file playable you might want to implement a custom source filter which streams data from internal buffer. 为了使文件可播放,您可能需要实现一个自定义源过滤器,该过滤器从内部缓冲区流式传输数据。 If data is not yet available, such filter would synchronize with download and serve file reading request as soon as data is arrived. 如果数据尚不可用,则此类过滤器将与下载同步并在数据到达后立即处理文件读取请求。 A custom filter built this way would replace File Source (Async) Filter on the pipeline, with the rest of pipeline built using the same filters. 以这种方式构建的自定义筛选器将用相同的筛选器构建的其余管道替换管道上的文件源(异步)筛选器。

Windows SDK Async Filter Sample (\\Samples\\multimedia\\directshow\\filters\\async) might be a good starting point for such custom filter. Windows SDK 异步过滤器示例 (\\ Samples \\ multimedia \\ directshow \\ filters \\ async)可能是此类自定义过滤器的良好起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM