Answered Two instances of Metro app

  • Tuesday, April 10, 2012 7:19 AM
     
     

    Hello,

    I wonder whether it is possible to run two instances of my Metro style audio player?

    I've found some threads, which says, that it is not possible, but it may change in further Windows 8 releases. My case is to run two audio files simultaneously.

    Best regards,

    Jiraiya

All Replies

  • Tuesday, April 10, 2012 7:33 PM
    Moderator
     
     Answered

    No. Metro style apps are single instance only.

    You could allow playing two audio files simultaneously in a single instance of the app.

    --Rob

  • Thursday, April 12, 2012 10:14 AM
     
     

    Hi Rob,

    Thanks for your reply. I developed a simple Metro app with two MediaElement objects in it. When I select via FileOpenPicker an audio file for first MediaElement, it started to play, which is OK. After that via second FileOpenPicker I selecte another audio file for second MediaElement and it started to play, but playback of first audio file stopped.

    Shall I do some extra work to enable simultaneous playback of two audio files? Does Media Foundation support that case?

    Some examples?

    BR,

    Jiraiya



    • Edited by Jiraiya2 Thursday, April 12, 2012 10:19 AM
    •  
  • Thursday, April 12, 2012 10:47 PM
    Moderator
     
     Proposed

    Hello Jiraiya,

    Try setting the AudioCategory to SoundEffects or GameEffects one of these should allow you to continue to play both streams at the same time.

    MediaElement.AudioCategory property
    http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.mediaelement.audiocategory.aspx

    If this doesn't work let me know and we will see what else we can come up with.

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

  • Friday, April 13, 2012 6:40 AM
     
     

    Hello James,

    I tried both AudioCategories you wrote above, but unfortunately without any positive effect. The application behavior hasn't changed.

    Best regards,

    Maciek

  • Monday, April 16, 2012 10:55 PM
    Moderator
     
     Answered Has Code

    Hello Jiraiya,

    This works for me:

    <Page
        x:Class="DualAudio.BlankPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:DualAudio"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{StaticResource ApplicationPageBackgroundBrush}">
            
            <StackPanel HorizontalAlignment="Left" Height="401" Margin="10,10,0,0" VerticalAlignment="Top" Width="793">
                <Grid HorizontalAlignment="Left" Height="100" Width="793">
                    <MediaElement x:Name="_ME1" AutoPlay="False" AudioCategory="GameMedia" HorizontalAlignment="Left" Height="100" Margin="0,00,0,0" VerticalAlignment="Top" Width="50" IsLooping="True" Source="Assets/atomic_dance_explosion_rad.mp3" MediaFailed="_ME1_MediaFailed" CurrentStateChanged="_ME1_CurrentStateChanged"/>
                    <Button x:Name="_btnPlay1" Content="Play" HorizontalAlignment="Left" Margin="696,27,0,0" VerticalAlignment="Top" Width="87" Click="_btnPlay1_Click"/>
                    <TextBox x:Name="_tbState1" HorizontalAlignment="Left" Margin="223,34,0,0" TextWrapping="Wrap" Text="Stopped" VerticalAlignment="Top" Width="277"/>
                </Grid>
                <Grid HorizontalAlignment="Left" Height="100" Width="793">
                    <MediaElement x:Name="_ME2" AutoPlay="False" AudioCategory="GameMedia" HorizontalAlignment="Left" Height="100" Margin="0,00,0,0" VerticalAlignment="Top" Width="50" IsLooping="True" Source="Assets/borg64.mp3" MediaFailed="_ME2_MediaFailed" CurrentStateChanged="_ME2_CurrentStateChanged"/>
                    <Button x:Name="_btnPlay2" Content="Play" HorizontalAlignment="Left" Margin="696,27,0,0" VerticalAlignment="Top" Width="87" Click="_btnPlay2_Click"/>
                    <TextBox x:Name="_tbState2" HorizontalAlignment="Left" Margin="223,34,0,0" TextWrapping="Wrap" Text="Stopped" VerticalAlignment="Top" Width="277"/>
                </Grid>
            </StackPanel>
    
        </Grid>
    </Page>

    Give this a try and let me know if you are still having problems.

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

  • Tuesday, April 17, 2012 9:35 AM
     
     

    James,

    Thanks for your reply. In fact it works great.

    But is it possible to do the same with FileOpenPicker for both MediaElements, so that I could choose during runtime what file to play, instead of explicitly selected in player code? - this is the way I'm following without positive results.

    Best regards,

    Maciek

  • Wednesday, April 18, 2012 12:59 AM
    Moderator
     
     

    Jiraiya,

    You should be able to use the file picker. Can you post your code?

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

  • Friday, April 27, 2012 12:48 AM
    Moderator
     
     

    Hello Jiraiya,

    Do you still need help with this?

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/