From my youth my grandmother was used to listening to the radio, but unfortunately, now you can hear far from the best songs and broadcasts on the radio. Radio can be replaced with your favorite music, but, alas, my grandmother has difficulty in getting used to the technique.
The best gift - a gift made by hand, so I, as a loving grandson and programmer for mobile platforms, began to think about how to provide my grandmother with easy access to her favorite music.
At once I will say that I have achieved success, but for those who are interested in the process - I ask for a cat.

Tasks
For a start, I set goals that I wanted to achieve:
- it is necessary to write an application that would have two modes: play music and listen to the radio;
- the application interface should be as simple as possible;
- the application should work with a memory card so that you can easily replace the source of the music;
- the application should not extinguish the screen, unless the lock key is pressed;
- if we exit the application, the music is turned off;
- The application in the process of playing audio should show the date, time and slideshow of the photo.
')
Iron selection
It was necessary to choose three things: an audio column, a stand for the smartphone and the smartphone itself.
Here, looking ahead, I will say that my choice is very controversial: it was possible to purchase other models with different characteristics and price. But how it happened, it happened.
Initially, I wanted the smartphone to be connected to a column via Bluetooth, since the less wires grandma has, the better. Therefore, the
Nokia MD-50W speaker was chosen: it is loud enough, it has a built-in battery, a standard micro-USB charging connector, Bluetooth and even NFC.
It was decided to choose the smartphone on the Windows Phone platform, since firstly, under this platform I have more development experience than under Android, and secondly, the system interface is quite simple for a person who has no experience at all with interfaces.
The development was carried out when the GDR2 update for Windows Phone 8.0 was just released, which added radio support. We also had to find a device with a microSD card and a bright, rather big screen. Just after a week of searching, the
Nokia Lumia 625 model was launched in Russia, which at that time was the only one that had GDR2, as well as the largest screen diagonally (4.7 ”).
So, the smartphone is traveling from Moscow, the column is from America, it remains to choose which docking station will get to me from China.
I forgot to mention that in everything I had to withstand the color style: the column and the smartphone were bought exclusively in white, because I took into account the interior in which this design was going to stand. It turned out that there are very few white docking stations with a microUSB connector. Apparently, because in China it is considered, once white means for Apple, once black means everything else. I also wanted to have a second notch on the docking station in order to be able to place the smartphone horizontally to view the video (you never know). This docking station was all alone. It was decided to order two: with add. notch and without.
Alas, China is saddened. Dock connector with add. the notch was exactly at right angles to the surface, which was very inconvenient. But in the docking station without a notch the connector was located as it should - at a slight angle. It was decided to simply glue the docking station together - it turned out a funny ladder, which, by the way, is more stable when you click on the smartphone, since it is twice as heavy.

Any Windows Phone has one unnecessary detail - the search button. If you put the USA region, and the default search is Bing, then yes - a more or less sensible application is launched, but in this context we don’t need this button at all, so we simply glue it in order not to click inadvertently. The idea spied on the staff of Yandex, even the sticker of the same name.

We fasten the radio
Here the next miscalculation was revealed. Since the radio in the smartphone uses headphones as an antenna, when wirelessly connected to the speaker, the radio simply does not turn on. Later it turned out to make it work through the code, but it worked exclusively through the built-in speaker. I had to connect the speaker to the smartphone with a cable.
In Windows Phone 8.0, for some reason, they did not immediately turn on the API for working with the radio, so it only works in updating GDR2 and higher (if there is hardware support for the radio, of course).
It turned out to be quite simple with radio:
FMRadio radioInstance = FMRadio.Instance;
Frequency - this is the frequency of the radio station, which we need to change. In the built-in program "Radio" there is a search mode for a radio station. Unfortunately, searches for its successful implementation have come to nothing.
It's okay: we measure the frequencies that are taken in the place where the smartphone will stand and simply prescribe with hardcode. Then we create buttons and hang them on each radio station. Buttons make big so that you can not particularly aim.
We add the “Back” button at the very top in order not to bother with the hardware buttons: in the Lumia 625, the hardware buttons are not highlighted, and it will be difficult to see the button on the screen.

We solve the problem with turning off the screen
So, the radio works. There are fears that even such a simple unlock gesture, like swipe up, will be difficult for the grandmother. So you need to minimize its use by disabling screen lock.
In different Windows Phone firmwares, there is a different set of time modes for turning off the screen. Nokia Lumia 920 (not AT & T) is generally the only Nokia on WP 8.0 that has the
“Disable Display via: Never” option. In other devices, this item is cut and costs a maximum of 5 minutes.
For comparison: Nokia 920 on the left, 1020 on the right (the same on AT & T 520, 620, 625, 720, 820 and 920).


But starting with GDR2, there are navigation programs that do not turn off the display - it means that this can be done somehow in the code. Ok, MSDN and find:
PhoneApplicationService phoneAppService = PhoneApplicationService.Current; phoneAppService.UserIdleDetectionMode = IdleDetectionMode.Disabled;
These lines keep the display on, unless the user himself has pressed the lock button. This is what you need.
We are friends of the application with a memory card
Now we need to implement work with a memory card. I want to appear on the screen buttons with the names of folders with music as well as in radio mode buttons with radio stations.
But there is a problem: Windows Phone can work with music, but only if the music is protected in the application itself (goodbye memory card and fast content replacement), or if the music always lies in the Music folder (goodbye work with folders).
The crutch was not found quickly.
First, in the
WMAppManifest.xml manifest
we inform the system that we will only recognize our file format on the memory card, and we will not notice the other files. And the format will contain mp3-content. Let the format be called, for example, “mp3d” (you can name it as you please, except for well-known extensions).
<Extensions> <FileTypeAssociation Name="mp3" NavUriFragment="fileToken=%s" TaskID="_default"> <SupportedFileTypes> <FileType ContentType="application/mp3">.mp3d</FileType> </SupportedFileTypes> </FileTypeAssociation> </Extensions>
The downside is that we will have to rename all mp3 files to mp3d files, but the ren team will do everything for us.
ren *.mp3 *mp3d
Now, we write a method that clings to the card and forms a list of subfolders of my music folder.
private async Task<List<ExternalStorageFolder>> ReadFoldersFromSdAsync() { List<ExternalStorageFolder> folders = new List<ExternalStorageFolder>();
We use this method by creating buttons and adding them to the list (omit the styles - they are in the source). In Tag I put the current folder, then to reach it by click (OnTap).
foreach (var f in folders) { IEnumerable<ExternalStorageFile> files = await f.GetFilesAsync(); if (files.Count() > 0) { Button button = new Button { Tag = f, Height = 85, Width = 456, Content = f.Name }; button.Tap += this.OnTap; ContentStack.Children.Add(button); } }
Inside OnTap-event shamanim: copy the mp3d file inside the application as an mp3 file
myFile.mp3 , take the URI of the copied file and feed the MediaElement as a resource:
IEnumerable<ExternalStorageFile> files = await folder.GetFilesAsync();
Music plays, moving on.
We write time on the screen saver
It was decided to make sure that after some time of inactivity (not a single button is pressed) the clock, the number and the day of the week appear on the screen.
In order for time to appear, we start a timer at one second intervals:
DispatcherTimer dtm = new DispatcherTimer(); dtm.Interval = TimeSpan.FromSeconds(1); dtm.Tick += OnTimerTick; dtm.Start();
In the event, we count the number of ticks and if it is 29, then we show the time on the screen:
private void OnTimerTick(Object s, EventArgs e) { UpdateDate(); _ticks++; if (_ticks == 29) {
When you click on any other button, we reset _ticks to zero.
In addition, the timer performs the function of updating the time once per second: we call a function that parses DateTime.Now and distributes it into text fields.
Add a slideshow
It’s just boring to look at the time, so we’ll make a background with a slideshow of photos. Where can I get a lot of photos of one size and aesthetically good content? From the Bing website!
I needed the photos of the same size due to the fact that it is very convenient to substitute them into the same animation: nothing will get off and not go in the wrong place.
On the torrents are archives, but there are photos of different sizes - will not work. There is
an excellent service that allows you to get Bing pictures, but pictures only under the smartphone screen (I want more), and only for the last week.
Finally, I
found an archive satisfying my requirements. It remains only to deflate.
The pictures were put in the Pictures folder on the phone itself.
The application was told to take these pictures one by one in a random order:
bg.Source = PictureDecoder.DecodeJpeg(_mediaLibrary.Pictures[_random.Next(_imageQuantity)].GetImage());
Then we draw an animation in which the Image object moves horizontally, and then changes the image to the next.

Draw icons
The Windows Phone interface turned out to be very helpful, as it turned out to bring huge shortcuts to applications on the desktop, for which you certainly would not miss. Since we are doing an elementary interface, the words were simply the words "Radio" and "Music."

Two shortcuts on
SPB TV were also brought to the desktop: Channel One and Culture.
We write instructions
No matter how hard I tried to make the interface simple, I could not predict how my grandmother would make friends with him, so I wrote instructions with screenshots and photos. I will publish the instruction together with the source code - suddenly someone will come in handy for the grandmother.
Results
Most importantly, my fear was not justified: less than two minutes passed, as I began to explain to my grandmother how to use the application, and she herself began to press buttons and shortcuts, put songs, close and open applications. I took the lock perfectly well, said it was like “raising or lowering the curtain”. So the goals were successfully achieved - now her favorite music sounds. A gift with your own hands was a success!
Sources and instructionsUPD:
At the request of workers add photos in the interior:
