Search code examples
c#exceptionaudiowindows-phone-8audiotrack

Windows Phone 8 Audiotrack Error - Why?


I'm trying to play an internet audio file in my app, but i'm having problems with large files. The code:

 var track = 
 new AudioTrack(
        new Uri(uri, UriKind.Absolute),
        "Podcast",
        string.Empty,
        string.Empty,
        null);

The "uri" var (string) when debugging contains a valid url: uri = "http://www.msftinsider.com/wp-content/uploads/2014/04/podcast_1.mp3", the AudioTrack object creates but there is no audio when play(). The error into the AudioTrack object:

AudioTrack Error

"Duration = 'track.Duration' threw an exception of type 'System.Runtime.InteropServices.COMException'"

{System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at Microsoft.Phone.BackgroundAudio.Interop.IAudioTrack.get_Duration() at Microsoft.Phone.BackgroundAudio.AudioTrack.get_Duration()}

Why? Thank you.


Solution

  •     string url = "http://www.msftinsider.com/wp-content/uploads/2014/04/podcast_1.mp3";
        AudioTrack audioTrack = new AudioTrack(new Uri(url), null, null, null, null, null, EnabledPlayerControls.None);
        BackgroundAudioPlayer.Instance.Track = audioTrack;
    

    This itself works for me.

    Also check my answer here:

    Windows Phone 8 - Streaming a Podcast MP3 file

    Just for info : For Streaming in windows 8.1 you have new API BackgroundAudioStreamer.