Reputation: 1867
I am working on windows phone 8 trying to implement the audio playing feature in my app by creating the user control and media element.
Surprisingly audio is playing during debugging but as i run the app without debug mode audio does not play, i tried the await and async methodology but thats also not working.
MainPage.xaml.cs
private async void AudioControl(string audioId, string audio_url)
{
customControlAudioPlayer.media_Id = audioId;
customAudioPlayer.media_Url = audio_url;
//Following function is dedicated to show control and play the audio.
await customAudioPlayer.RenderView();
gridContainsMediaElement.Visibility = Visibility.Visible;
}
MainPage.xaml
xmlns:MyControls="clr-namespace:dbok.Controls"
<Grid Name="gridContainsMediaElement"
VerticalAlignment="Top"
Background="Black" Visibility="Collapsed">
<MyControls:AudioPlayerControl
x:Name="customControlAudioPlayer"/>
<!--CloseClick="audioPlayerControl_CloseClick"-->
</Grid>
CustomControlPlayer.xaml
<Grid Background="{StaticResource PhoneChromeBrush}" >
<MediaElement x:Name="audioMediaElement" AutoPlay="False"
Grid.Row="0"
MediaOpened="audioMediaElement_MediaOpened"
MediaEnded="audioMediaElement_MediaEnded"
MediaFailed="audioMediaElement_MediaFailed"
HorizontalAlignment="Center" Height="05"
VerticalAlignment="Center"/>
<Slider Visibility="Visible" Margin="50,0,50,0"
x:Name="mediaPositionSlider" Background="#f1592a"
Minimum="0" Grid.Row="0"
/>
</StackPanel>
</Grid>
CustomControlPlayer.xaml.cs
public string media_Id;
public string media_Url;
public async Task RenderView()
{
Uri file_url;
if (Uri.TryCreate(media_Url, UriKind.Absolute, out file_url))
{
myElement.Source = file_url;
myElement.Play();
//I tried by check the media element state but its executing and playing only in debug mode. it was not working for me without debug i made it commented.
//if (myElement.CurrentState != MediaElementState.Playing)
//{
// myElement.Play();
//}
mediaPositionSlider.Value = 0;
UpdateDuration(0);
}
//-----------
private void UpdateDuration(double _myValue)
{
TimeSpan t = TimeSpan.FromSeconds(_myValue);
string time_slot = string.Format("{0:D2}:{1:D2}:{2:D2}",
t.Hours,
t.Minutes,
t.Seconds);
PlayStatusLabel.Text = time_slot.ToString();
}
I have post my code, where & what i am doing wrong by which its not playing in run mode inplace of debug mode ?
Upvotes: 0
Views: 544
Reputation: 1867
I have successfully solved the issue i was facing, actually what happening when cursor reach on audioMediaElement.Play(); the Play() function takes time to execute internally, what i did i replace audioMediaElement.Play() to audioMediaElement.AutoPlay = true; and it started working. :) woooo hoooo... :)
Upvotes: 1