Good day, Hashcode.
Is there a way to start playing a media file in Windows Phone while it is still loading?
At the moment I have an application with the ability to download and play media files. (This is described in this article)
Specifically: first, the media file is loaded, and only then, after a full load, the path to the isolatedStorageFileStream is written to mediaElement.source
. After that, the file can already be played.
And you want to do better - to give the opportunity to play the file when the download is still underway. Ultimately, it will look something like this: the file is being downloaded, the file is being decrypted in parallel, this file can be started in parallel at the same time. For the time being, let's forget about decryption :), especially since I already wrote it for the finished file. It remains to understand what to do with playing.
As I understand it, mediaElement
allows mediaElement
to transfer to the source
only "solid" files, without the possibility of adding something to this file. Perhaps, when downloading, you must immediately take the media from the stream, and not from the file where it is written, I don’t know, I’m a noob in this business.
How can this be done? What to use for playing media, because mediaElement
does not seem to fit.
While the boot process is implemented as follows:
WebClient webClient = new WebClient(); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged); webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted); webClient.OpenReadAsync(new Uri(link));
Next in OpenReadCompleted is the downloaded file and
mediaFile.SetSource(isolatedStorageFileStream);
PS By default, we assume that we work only with audio files of mp3 format, there is no video.
There is, for example, such a thought. When launching a page with mediaElement, check if there is such a file in IsolatedStorage. If there is, then perform the sequence described above, if not, then simultaneously start downloading the file to IsolatedStorage and use something to play the stream, such as Background Audio Agent (although this stream will also have to be decrypted immediately ...).
Is it actually possible to do this, or am I already leaving for magic? With the Background Audio Agent, affairs until now had no way to work with him, while without a clue, these were purely theoretical reflections.