You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/09/01 04:30:34 UTC
[7/7] wp7 commit: MediaElement only supported one at a time, CB-941,
CB-988
MediaElement only supported one at a time, CB-941, CB-988
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/86611cd1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/86611cd1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/86611cd1
Branch: refs/heads/master
Commit: 86611cd1e07f72f19e01396f0ea067ae363b2467
Parents: 7cc000f
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Aug 31 03:02:13 2012 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Aug 31 03:02:13 2012 -0700
----------------------------------------------------------------------
.../standalone/cordovalib/Commands/AudioPlayer.cs | 38 +++++++++------
templates/standalone/cordovalib/Commands/Media.cs | 20 ++++++--
2 files changed, 38 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/86611cd1/templates/standalone/cordovalib/Commands/AudioPlayer.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/AudioPlayer.cs b/templates/standalone/cordovalib/Commands/AudioPlayer.cs
index 35d805c..43ae237 100644
--- a/templates/standalone/cordovalib/Commands/AudioPlayer.cs
+++ b/templates/standalone/cordovalib/Commands/AudioPlayer.cs
@@ -228,35 +228,43 @@ namespace WP7CordovaClassLib.Cordova.Commands
}
- if (this.player == null)
+ if (this.player == null || this.player.Source.AbsolutePath.LastIndexOf(filePath) < 0)
{
try
{
- if (this.player == null)
+ // this.player is a MediaElement, it must be added to the visual tree in order to play
+ PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
+ if (frame != null)
{
- // this.player is a MediaElement, it must be added to the visual tree in order to play
- PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
- if (frame != null)
+ PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
+ if (page != null)
{
- PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
- if (page != null)
+ Grid grid = page.FindName("LayoutRoot") as Grid;
+ if (grid != null)
{
- Grid grid = page.FindName("LayoutRoot") as Grid;
- if (grid != null)
- {
+ //Microsoft.Xna.Framework.Media.MediaPlayer.Play(
+ this.player = grid.FindName("playerMediaElement") as MediaElement;
+ if (this.player == null) // still null ?
+ {
this.player = new MediaElement();
this.player.Name = "playerMediaElement";
grid.Children.Add(this.player);
- this.player.Visibility = Visibility.Collapsed;
- this.player.MediaOpened += MediaOpened;
- this.player.MediaEnded += MediaEnded;
- this.player.MediaFailed += MediaFailed;
+ this.player.Visibility = Visibility.Visible;
+ }
+ if (this.player.CurrentState == System.Windows.Media.MediaElementState.Playing)
+ {
+ this.player.Stop(); // stop it!
}
+
+ this.player.Source = null; // Garbage collect it.
+ this.player.MediaOpened += MediaOpened;
+ this.player.MediaEnded += MediaEnded;
+ this.player.MediaFailed += MediaFailed;
}
}
-
}
+
this.audioFile = filePath;
Uri uri = new Uri(filePath, UriKind.RelativeOrAbsolute);
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/86611cd1/templates/standalone/cordovalib/Commands/Media.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/Media.cs b/templates/standalone/cordovalib/Commands/Media.cs
index 389abb1..56076bd 100644
--- a/templates/standalone/cordovalib/Commands/Media.cs
+++ b/templates/standalone/cordovalib/Commands/Media.cs
@@ -219,13 +219,18 @@ namespace WP7CordovaClassLib.Cordova.Commands
}
}
+ // Some Audio Notes:
+ // In the Windows Phone Emulator, playback of video or audio content using the MediaElement control is not supported.
+ // While playing, a MediaElement stops all other media playback on the phone.
+ // Multiple MediaElement controls are NOT supported
+
// Called when you create a new Media('blah') object in JS.
public void create(string options)
{
+ // Debug.WriteLine("Creating Audio :: " + options);
try
{
MediaOptions mediaOptions;
-
try
{
string[] optionsString = JSON.JsonHelper.Deserialize<string[]>(options);
@@ -259,14 +264,16 @@ namespace WP7CordovaClassLib.Cordova.Commands
try
{
MediaOptions mediaOptions;
-
try
{
string[] optionsString = JSON.JsonHelper.Deserialize<string[]>(options);
mediaOptions = new MediaOptions();
mediaOptions.Id = optionsString[0];
mediaOptions.Src = optionsString[1];
- mediaOptions.Milliseconds = int.Parse(optionsString[2]);
+ if (optionsString.Length > 2 && optionsString[2] != null)
+ {
+ mediaOptions.Milliseconds = int.Parse(optionsString[2]);
+ }
}
catch (Exception)
@@ -284,7 +291,7 @@ namespace WP7CordovaClassLib.Cordova.Commands
}
else
{
- Debug.WriteLine("INFO: startPlayingAudio could not find mediaPlayer for " + mediaOptions.Id);
+ Debug.WriteLine("INFO: startPlayingAudio FOUND mediaPlayer for " + mediaOptions.Id);
audio = Media.players[mediaOptions.Id];
}
@@ -323,7 +330,10 @@ namespace WP7CordovaClassLib.Cordova.Commands
string[] optionsString = JSON.JsonHelper.Deserialize<string[]>(options);
mediaOptions = new MediaOptions();
mediaOptions.Id = optionsString[0];
- mediaOptions.Milliseconds = int.Parse(optionsString[1]);
+ if (optionsString.Length > 1 && optionsString[1] != null)
+ {
+ mediaOptions.Milliseconds = int.Parse(optionsString[1]);
+ }
}
catch (Exception)
{