Reputation: 1291
I am going to write an application that will play two audio streams simultaneously from an HTTP streaming server. Before I begin, I want to be sure whether the Windows Phone devices and API supports this.
I guess I'll have to use two instances of MediaElement's. Any ideas or suggestions?
Edit: I tried it with the following code, and the first one stops and second one plays, when I start the second one while the first one is playing:
private void StopMedia1(object sender, RoutedEventArgs e)
{
media1.Stop();
}
private void PauseMedia1(object sender, RoutedEventArgs e)
{
media1.Pause();
}
private void PlayMedia1(object sender, RoutedEventArgs e)
{
media1.Play();
}
private void StopMedia2(object sender, RoutedEventArgs e)
{
media2.Stop();
}
private void PauseMedia2(object sender, RoutedEventArgs e)
{
media2.Pause();
}
private void PlayMedia2(object sender, RoutedEventArgs e)
{
media2.Play();
}
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<MediaElement x:Name="media1" Source="1.mp3" Margin="0,151,0,359" />
<MediaElement x:Name="media2" Source="2.mp3" Margin="0,154,3,359" Grid.Column="2" />
<!-- Stops media playback.-->
<Button Click="StopMedia1" Content="Stop" Margin="6,449,24,244" />
<!-- Pauses media playback. -->
<Button Click="PauseMedia1" Content="Pause" Margin="0,538,24,143" />
<!-- Begins media playback. -->
<Button Click="PlayMedia1" Content="Play" Margin="0,649,0,47" />
<Button Click="PauseMedia2" Content="Pause" Grid.ColumnSpan="2" Margin="154,524,6,169" Grid.Column="1" />
<Button Click="PlayMedia2" Content="Play" Grid.Column="2" Margin="0,612,12,59" />
<Button Click="StopMedia2" Content="Stop" Margin="18,429,12,264" Grid.Column="2" />
</Grid>
Thanks in advance.
Upvotes: 0
Views: 276
Reputation: 4359
No, it is not possible to play two MediaElements at the same time in Windows Phone 7/7.5. To do that you would need to use the SoundEffect class from XNA, althought I don't think that supports streaming.
Upvotes: 1