Part 3: Handle Media Devices Using History State
Usually there are various Media devices available in an IVI. The user can choose a certain device in the Media context. He can leave the Media context and switch to e.g. Navigation. Once he comes back to the Media scene, the correct selected Media device will be displayed.
To achieve this with Scene Composer we need to create a similar configuration to the what we have already done for Navigation, Media and Phone: We will need separate states for our Media devices Radio, Bluetooth and USB. We will also need to configure transitions between these states in both directions (from Radio to Bluetooth, from Bluetooth to Radio etc).
Within these Media States we also have to keep track of the currently selected Media device. This will be handled by a History State.
Create a Sub Chart for Media
This chart will be created inside the Media State. Its starting point will be an Initial State, so drag and drop an initial state onto the Media State.


Additionally we will need to add separate states for Radio, Bluetooth and USB. In order to find enough space for these states, we could enlarge the media state using the resize handles in the corners of the selected media state.
A more elegant way is to create a subchart. Select the Media State in the State Machine Editor and press the right mouse button. From the context menu choose Convert to subchart.


As you can see in the State Machine Editor, a subchart "Media" will be created. The new structure also appears in the panel on the left in State Machine Editor.


The inner state "Media" can also be renamed by selecting the name in the left panel and changing the name in the properties panel (or using the keyboard shortcut F2).
This inner state "Media" can be accessed by double-clicking the initial state in the State Machine Editor or by double-clicking it in the panel.


The next step is to add states for the media devices and transitions between them into the subchart. In order to have enough space for the states resize the SubChart State using the resize handles of the selected Media_SubChart state, that appear when it is selected.


Add States for Media Devices
Our sample IVI will provide three Media Devices. So, let's add the following three states into the subchart:
- Radio
- Bluetooth
- USB
Configure the States - OnEntry and OnExit Actions
We have to configure what happens when the states are entered and when they are exited. Our configuration here will be similar to what we did for Navigation, Media and Phone.
When a state is entered, we have to activate the respective Scene with a TransitionRequest. When the state is exited, the Scene has to be deactivated again with a TransitionRequest.


Additionally, we want the Media_Menu Scene to display the currently active Media Device. This is also configured with an OnEntry and an OnExit Action.


Configure all States (Radio, USB and Bluetooth) in a similar way:


Insert Transitions
Now it's time to draw a transition from the Initial State to the Radio State, which will be our default media device. Connect the states with transitions into both directions (similar to what we did for Navigation, Media and Phone) Between the 3 states Radio, USB and Bluetooth we need transitions in both directions:
|
|
The resulting subchart will look as follows.


Configure State Transitions
The user should be able to navigate from one media device to the other using the up and down arrow key. This can be configured in the transitions (similar to navigating between Navigation, Media and Phone).
All clockwise transitions (named *_next) will be configured for Key_DownArrow and all counter-clockwise transitions (named *_prev) will be configured for Key_UpArrow.


Add History State
When you save your solution and start the player now, you can switch from Navigation to Media using the Key_RightArrow. Use the Key_DownArrow to change the Media Device. Use the Key_RightArrow to navigate to Phone. If you now press the Key_LeftArrow to go back to Media, you will see that "Radio" is selected again, although you have chosen a different device earlier.
To handling such use cases, you need to replace the Initial State of the Media_SubChart with a History State. Open the Media_SubChart in the State Machine Editor, select the Initial State and press the delete key. The Initial State and its transition to the Radio State will be deleted. Now, drag and drop a History State into the Media_SubChart.


Draw a transition from the History State to the Radio State, our default Media Device.
The History State will remember which state was active last time and perform the transition to the correct Media Device.


Test the Configuration - Start the Player
Save your solution and start the player.


After the Player is opened, you can see the Navigation Scene. When Pressing the Key_RightArrow, the transition to the Media scene is performed and the selected device is the default device "Radio". If you press the Key_DownArrow to change the selected media device, USB will be the selected device.


Key_LeftArrow. The Media Scene should be visible again, displaying the USB device. This means that the History State is working, it has brought us back to the recently selected device.

