0
votes

I have a WP7 application that I run successfully on both WP7 and WP8 devices. In the app I download audio files using the BackgroundFileTransfer service and store the files to the shared/transfers folder. I then create AudioTracks by giving a URI to the downloaded file locations.

        Uri episodeLocation;
        try
        {
            using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
            {
                Debug.WriteLine(" *** Creating track, file exists: " + iso.FileExists("shared/transfers/song.mp3"));
            }
            episodeLocation = new Uri("shared/transfers/song.mp3", UriKind.Relative);
        } catch(Exception) {
            return null;
        }

        return new AudioTrack(episodeLocation,
                        "Track name",
                        "Album name",
                        "",
                        new Uri("/path/to/logo", UriKind.Relative));

This works great on both Windows Phone 7 and Windows Phone 8 devices - audio player is able to play the track just fine. The debug output prints True as the result for the test if file exists.

I've now converted the application in Visual Studio 2012 to be a Windows Phone 8 application. If I now run the application in Windows Phone 8, I get a System.IO.FileNotFoundException external exception from the player. Also in the converted version the debug output prints True when checking if the file exists.

I only converted the app from a WP7 to WP8 app and I cannot refer to files in shared/transfers any more.

Why?

What's the proper way to do this?

I already tried referring to the files by using the URI isostore:/shared/transfers/song.mp3 but that didn't seem to have an effect.

2
In fact, it seems moving the audio files to any other directory or even the root directory yields the same result: FileExists() returns true, but Audio player throws FileNotFound exception.Johan Paul

2 Answers

0
votes

What I did was that I now created a completely new and empty WP8 project and then I copied over all the old code from the WP7 project to this new WP8 project and I then rebuilt the solution. I did no code modifications whatsoever from the version that I had when I wrote this post, I converted from a WP7 project to an WP8 and that has issues.

Audio player is again able to play the audio files.

So an advice to anyone with WP7 projects: Do not convert them in Visual Studio to WP8 projects as wierd things can happen.

0
votes

Ok - I fink I've found it - in my case the problem is that my BackgroundDowload needs an Uri file location, I create Uri like this:

fileName = "shared/transfers/my filename.txt";
fileName = Uri.EscapeUriString(fileName);
Uri fileUri = new Uri(fileName, UriKind.Relative);

With or without second line of the code above, file is saved to a location of escaped string format. It seems to be like this, becouse it's provided as Uri. The file is downloaded and as you mentioned, it's created and exists as FileExists() shows. I've my 'escaped' fileName and when I want to (for example) play an audio I do something like this:

return new AudioTrack(new Uri(Uri.EscapedUriString(fileName), UriKind.Relative), title ....);

Hope it helps you as it works for me.