Playlist LoadAsync Issue (Playing MP3 from created playlist) RRS feed

  • Question

  • I am making my first Windows 8 application. It is a music app that when I press play it has already created a playlist of songs in my music folder and will play them one after each other. I've trying to get it to load the saved playlist but not sure if I set the async correctly. When I click play get this "Unhandled exception at 0x012EA681 in MyApp.exe: 0xC0000005: Access violation reading location 0x00000000."

    Below is the function I am using to create the playlist by querying for all the mp3s. Then it is the play_music function which is giving me trouble, I believe this is where my error might be. I am essentially combining the MediaStreamSource example (for all the mp3 playing code) and the  FileSearch example. Any code not shown is from those examples. Any thoughts are appreciated, I'm pretty stumped. 

    void MyApp::MusicApp::GetQueryList()
    	auto musicFolder = KnownFolders::MusicLibrary;
    	auto fileTypeFilter = ref new Platform::Collections::Vector<Platform::String^>();
    	auto queryOptions = ref new QueryOptions(CommonFileQuery::OrderBySearchRank, fileTypeFilter);
    	//use this query to get all MP3s listed in Music Folder
    	queryOptions->UserSearchFilter = ".mp3";
    	auto queryResult = musicFolder->CreateFileQueryWithOptions(queryOptions);
    	//find all files that match the query
    	create_task(queryResult->GetFilesAsync()).then([this, queryOptions](IVectorView<StorageFile^>^ files)
    		//Create playlist with files found in Music Folder
    		if (files->Size > 0)
    			Playlist^ playlist = ref new Playlist();
    			for each (StorageFile^ file in files)
    			StorageFolder^ folder = KnownFolders::MusicLibrary;
    			String^ name = "myPlaylist";
    			NameCollisionOption collisionOption = NameCollisionOption::ReplaceExisting;
    			PlaylistFormat format = PlaylistFormat::WindowsMedia;
    			task<StorageFile^>(playlist->SaveAsAsync(folder, name, collisionOption, format)).then([this](StorageFile^ file)
    				//PLaylist Created
    void myApp::MusicApp::play_music()
    	//Get music file
    	StorageFolder^ Folder = KnownFolders::MusicLibrary;
    	String^ Filename = "myPlaylist.wpl";
    	task<StorageFile^> getFileTask(Folder->GetFileAsync(Filename));
    	getFileTask.then([this](StorageFile^ file)
    		return Playlist::LoadAsync(file);
    	}).then([this](Playlist^ value)
    	inputMP3File = value->Files->GetAt(0);

    Tuesday, February 25, 2014 9:53 PM

All replies

  • Step through in the debugger to see exactly which line gives you the error. Access violation suggests that you are trying to dereference a null pointer, and the debugger will let you look at your variable values to find that.

    If you need help debugging it please post a minimal sample demonstrating the problem to your OneDrive and share a link.


    Wednesday, February 26, 2014 4:58 AM