Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

c# - Playing background audio and video both at same time

I need to develop windows phone application. In that in the page i need to run background audio and video continuously (in repeat mode).

For Audio, i found this example.

Now how do i add background video in the page? In the page i need to show some textboxes and buttons and in the background video and audio both will play.

Both audio and video file will be included in the application i.e. no steaming is needed.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I actually did this for a work assignment of mine a few months back. I found out that Silverlight for WP7 did not allow me to have two MediaElements playing at the same time. What I did was create a Windows Phone Silverlight and XNA Application. (Now Silverlight for WP7 finally created a background audio player so you can do it that way if you would like)

Your application can be entirely in Silverlight, but then you can use the XNA referenced (also you can have access to an update loop which is really nice)

XNA has a SoundEffect and SoundEffectInstance class

Then to load a sound just do the following:

Globals in you wrapper class Sound.cs

private SoundEffect Sound = null;
private SoundEffectInstance Instance = null;

Playing a Sound Effect in Sound.cs

Sound = ContentManager.Load<SoundEffect>(fileName); //ContentManager will have to be instantiated from wherever you create it.
Instance = Sound.CreateInstance();
Instance.Play();

Then just use the Silverlight MediaElement to play your video file.

XAML

<MediaElement x:Name="VideoPlayer" AutoPlay="False" Width="320" Height="220"/>

CodeBehind

VideoPlayer.Source = = new Uri("fileName", UriKind.Relative);
VideoPlayer.Play();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...