Showing posts with label emulator. Show all posts
Showing posts with label emulator. Show all posts

Friday, 22 March 2013

How to add songs to the emulator's MediaLibrary

    One of the new features of the Windows Phone 8 SDK is the ability to save(add) songs to the phone's MediaLibrary. This is a really nice when you add songs to the MediaLibrary any other music application that you have installed on your phone can play the songs that your application has saved.. The SaveSong method is found in the MediaLibraryExtensions class. Here are the parameters of this method:

[ExtensionAttribute]

public static Song SaveSong (
MediaLibrary library,
Uri filename,
SongMetadata songMetadata,
SaveSongOperation operation
)
    The method requires the ID_CAP_MEDIALIB_AUDIO capability and will return a reference to the newly saved song. One of the things that the documentation forgot to mention is that the filename Uri has to be an Uri to a file on the IsolatedStorage. You cannot give a direct Uri to an asset file (this I think because using the SaveSongParameter you can choose if you want to copy or move the file to the MediaLibrary) as you will get InvalidOperationException. If you want to add a song deployed as an asset you will first have to copy the file to the IsolatedStorage and then save it to the MediaLibrary.

    To copy the file to the IsolatedStorage you can use the:
 var resource = Application.GetResourceStream(new Uri(@"Assets/Songs/"+fileName, UriKind.Relative));  
resource.Stream.CopyTo(fileStream, 4096);


or you can use the WinRT Api to read the asset file:
  songUri=new Uri("ms-appx:///Assets/Songs/"+fileName,UriKind.Absolute);  
var file=await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(songUri);
 
    One interesting parameter is the SongMetadata. This enables you to "mess" with the metadata that will be saved to the MediaLibrary. If this parameter is null then the function will automatically import the file's metadata. If you still want to verify/import just some of the files metadata you can use the PCL ID3.NET and read the metadata of the file you have on the Isolated Storage. The portble dll is Id3.dll. You just have to pass the Stream to the Mp3Stream method:

 Id3.Mp3Stream mp3 = new Id3.Mp3Stream(resource.Stream);  
if (mp3.HasTags)
{
}


NAMASTE

Wednesday, 2 January 2013

Saving the Windows Phone 8 Emulator State

    Saving the emulator state between runs was one of the feature needed for the Windows Phone emulator, but till now it is not officially supported. It even makes more sense now when the Windows Phone 8 emulator is a full working operating system and not a trimmed one like Windows Phone 7/7.5 was. You could configure an email account, personalize the start screen, install some applications, install certificates or even save the state of an application that requires a lot of data to synchronize before the actual debugging and have everything ready the next time you start the emulator.
   Today I was trying to run the Windows Phone 8 emulator on a Parallels 8 machine using this post because I hate Windows 8 performance in Bootcamp (the disk access is crappy and the UEFI mode still needs drivers for sound, video and a way to enable Hyper-V). I observed that the first time you run an Windows Phone emulator it took more than 40 seconds to start. The reason is that the SDK creates a new Virtual Machine in Hyper-V and saves a "clean" snapshot of it.

       On every subsequent run of that emulator the XDE automatically starts the virtual machine and immediately applies the snapshot (or starts the virtual machine from the snapshot directly). What caught my attention was the name of the snapshot for each virtual machine: 
  1. Emulator 720P - snapshot.720x1280.1024
  2. Emulator WVGA 512MB - snapshot.480x800.512
  3. Emulator WVGA - snapshot.480x800.1024
  4. Emulator WXGA - snapshot.768x1280.1024
     I tried and messed up the names and observed that XDE, if it doesn't see a certain Snapshot, it starts the Virtual Machine and creates a new snapshot with the required name. So in order to save the state it would be enough to alter/change the snapshot XDE uses to start the virtual machine. 
      First we need to start the emulator we want to personalize (in this post i will mess up the 512 WVGA emulator). This can be done in two ways:
  1. From Visual Studio by running a program on that emulator or from Application Deployment (the emulator is easy to personalize because you can zoom the content and you have the hardware buttons but will require a subsequent reset of the Virtual Machine from Hyper-V) 
  2. From Hyper-V manager by starting the Emulator WVGA 512MB virtual machine and applying the saved snapshot for a fast start. After the machine starts you will have to connect to it:

    Once connected to the emulator/virtual machine you can personalize/modify the way you want it to be. If you connected using Hyper-V these keyboard shortcuts will prove helpful (they also work in the emulator):


  • F1 - the same as pressing the back button
  • F2 – the same as pressing the home button
  • PageUp  - enables physical keyboard and minimizes the software keyboard
  • PageDown – disables physical keyboard and maximizes the software keyboard
  • F9 - volume up
  • F10 - volume down
  • F7 – invoke camera
  • F3 – invoke Bing search
If you want/need to install some xap's you can use Application Deployment with the Emulator. 
When you've reached the desired state go to the Hyper-V manager, select the Virtual machine that you are personalizing and hit Snapshot. This will create a new Snapshot(save state for the emulator).

If you've started the emulator from Visual Studio or Application Deployment App before you create the snapshot you will have to connect to the Virtual Machine from Hyper-V and from the menu Action select Reset (this will clean the ports used for debugging and the state you will save will be usable for Visual Studio and XDE).

After saving the new state the only thing you have to do is to rename the snapshot with the same name of the parent snapshot and delete the parent by right-clicking on it and select Delete Snapshot (DO NOT select Delete Snapshot Subtree).

You are now ready to go:  Turn Off the virtual machine from Hyper-V and try it from Visual Studio. Everything should work. If it doesn't it means that the state has some ports that Visual Studio uses still opened and in this case you will have to connect to the Virtual Machine from Hyper-V, Reset the machine from Action and save a new Snapshot.


My personalized emulator looks like this:


If you want to get back to an "unaltered" state just delete the snapshot of the corresponding Virtual Machine from Hyper-V Manager.


Hope saving the emulator state will help you in some scenarios.

NAMASTE!

Friday, 31 August 2012

Windows Phone 8 inside VMWare

    More than a month ago some Microsoft guy in Asia made a terrible mistake and the LKG25 of Windows Phone 8 SDK leaked to the web. As I am not one of the lucky people that are the development program (as Mary Jo Foley suspected in a tweet and I believe it is true) I was more than happy when I got my hands onto the leaked version. At start I wanted to start blogging about the news that Windows Phone 8 will bring, but then I decided that it wouldn't be fair so I will wait until the official SDK. This post is not intended as a spoiler of any feature from WP8, but more like a proof of concept.
    I am sure many of you read on twitter that the new emulator is a virtual x86 machine and it comes with the virtual hard drive (.vhd file) divided on the screen resolutions.
    The idea came to me today while I was installing a clean virtual machine for development. Till now developing in a virtual machine for Windows Phone and debugging on the emulator with a decent speed/quality was impossible as you would have a virtual machines inside a virtual machine that degrades the performance exponentially. So what if you could have the development environment inside a virtual machine and then the emulator on another virtual machine that runs side by side and communicate on TCP/IP. In this case the performance of the emulator would be good (as it is not a vm inside a vm) and also the speed of the development environment would be acceptable. The virtual machine for the emulator would need 512MB or a maximum of 1GB.
     So the first thing I did is to install a trial version of VMWare Workstation 9 (should work with VMWare Fusion and also Parallels/VirtualBox). Then I have used WinIMAGE to convert the Flash.vhd file to Flash.vmdk which is the format that VMWare uses and created a virtual machine where I've attached the newly created vmdk.


     The good news is that the virtual machine works in VMWare right from the start. Not everything works (more decent is to say that some things work :) ) but hey it runs and I did nothing. The networking is not working but the most annoying part is the mouse pointer which is invisible in the virtual machine so I am blind pressing the mouse and at some point I am able to hit some buttons as you can see in the video :



More important than what this video shows (which is almost nothing) is what it could mean (even if I doubt we will see any of these in the near feature)


  • Theoretically developing for Windows Phone 8 on Windows 7 should be possible and not so hard to achieve (the partition where I installed Vmware Workstation runs Windows 7)

  • With some collaboration between Microsoft and VMWare/Parallels it would be possible to develop on a virtual machine and debug/deploy on the emulator which is another virtual machine. This would be great for Mac users but also for everyone (I might say like me) that likes to keep his development environments clean and separated from each other (I have a VM with VS2008 and Compact Framework, soon VS2010 will pass in a virtual machine too, I don't want to install VS2010 on my Windows 8 partition etc.)


  • The emulator is an x86 virtual machine so it shouldn't be so hard to achieve plug-gable hardware into the emulator (like connect the webcam to the emulator camera, storage card to an USB key or shared folder, NFC hardware - here I might be mistaking but should be a serial connection after all). It would give us a better development environment.

P.S. Seeing that it is a virtual machine I beg the team which is in charge of the emulator to SAVE the emulator/virtual machine state between resets. It is really annoying to always start from 0 and none of the other major mobile platforms has this limitation.


Till next time NAMASTE to you my reader.

Thursday, 17 February 2011

WP7 Emulator Tip: Use your hardware keyboard

   Yesterday at MWC I was telling Bryan Agnetta how frustrating it is not to be able to use you hardware keyboard to input text in the Emulator and he told me that as long as he knows there is some shortcut that enables the hardware keyboard in the emulator. Searching with google I've found a post on Brad Tutterow's blog and in fact you can use PgUp to enable the hardware keyboard in the emulator. Hope this tip will help you as much as it helps me. No more frustration...:)

 Here are all the shortcuts:


Page up / page down: Toggle between the software keyboard on the emulator and the hardware keyboard on your development machine.  While using your machine’s keyboard, you can TAB between fields.
F1: Back
F2: Start
F3: Search


Thursday, 18 March 2010

WP7 Emulator "Unlocked"

I still cannot believe it but I did it... After a good idea, 6 hours of work and a lot a lot of digging I've unlocked the ROM image in the emulator CTP. I will describe tomorrow the method but right now I will just post some screenshots, upload the bin somewhere so I can give you the link and go to sleep cause it's almost 2 o'clock in the morning.


I will also test it better tomorrow put I saw that it has a file explorer :) and a VERY nice task manager:

I have decided to take down the link because Microsoft could get upset and I don't really want that (if someone at Microsoft will tell me that it doesn't bother them I will put it back).

Anyway I will explain later how I was able to do it (cause it was done for educational purposes only) and I think this won't cause me problems. Right? :)