Skip to content

Commit

Permalink
Merge pull request #19 from purplecabbage/MediaPlaybackError
Browse files Browse the repository at this point in the history
Audio playback issue CB-142
  • Loading branch information
Jesse MacFadyen committed Jan 13, 2012
2 parents 32edf51 + e1bc2c7 commit d34f29b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 54 deletions.
22 changes: 1 addition & 21 deletions example/www/audio.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE HTML>
<!DOCTYPE html>
<html>
<head>
<!-- meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=2.0, maximum-scale=4.0, minimum-scale=1.0" / -->
Expand All @@ -7,26 +7,11 @@
<title>PhoneGap</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen">

<script type="text/javascript">
// provide our own console if it does not exist, huge dev aid!
if (typeof window.console == "undefined") {
window.console = { log: function (str) { window.external.Notify(str); } };
}

// output any errors to console log, created above.
window.onerror = function (e) {
console.log("window.onerror ::" + JSON.stringify(e));
};

console.log("Installed console ! ");
</script>

<script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>


<script type="text/javascript" charset="utf-8">

var deviceReady = false;

//-------------------------------------------------------------------------
// Audio player
Expand Down Expand Up @@ -235,11 +220,6 @@
deviceReady = true;
console.log("Device="+device.platform+" "+device.version);
}, false);
window.setTimeout(function() {
if (!deviceReady) {
alert("Error: PhoneGap did not initialize. Demo will not run correctly.");
}
},1000);
}

</script>
Expand Down
22 changes: 1 addition & 21 deletions example/www/capture.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
<!DOCTYPE HTML>
<!DOCTYPE html>
<html>
<head>
<!-- meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=2.0, maximum-scale=4.0, minimum-scale=1.0" / -->
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
<title>PhoneGap</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen"/>

<script type="text/javascript">
// provide our own console if it does not exist, huge dev aid!
if (typeof window.console == "undefined") {
window.console = { log: function (str) { window.external.Notify(str); } };
}

// output any errors to console log, created above.
window.onerror = function (e) {
console.log("window.onerror ::" + JSON.stringify(e));
};

console.log("Installed console ! ");
</script>

<script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>


<script type="text/javascript" charset="utf-8">

var deviceReady = false;

// last captured media file
var mediaFile = null;
Expand Down Expand Up @@ -151,14 +137,8 @@
*/
function init() {
document.addEventListener("deviceready", function () {
deviceReady = true;
console.log("Device=" + device.platform + " " + device.version);
}, false);
window.setTimeout(function () {
if (!deviceReady) {
alert("Error: PhoneGap did not initialize. Demo will not run correctly.");
}
}, 1000);
}

/**
Expand Down
29 changes: 19 additions & 10 deletions framework/PhoneGap/Commands/AudioPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using Microsoft.Phone.Controls;

namespace WP7GapClassLib.PhoneGap.Commands
{
Expand Down Expand Up @@ -229,21 +230,29 @@ public void startPlaying(string filePath)
{
if (this.player == null)
{

if (!Application.Current.Resources.Contains("PhoneGapMediaPlayer"))
// 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)
{
throw new Exception("PhoneGapMediaPlayer wasn't found in application resources");
PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
if (page != null)
{
Grid grid = page.FindName("LayoutRoot") as Grid;
if (grid != null)
{
this.player = new MediaElement();
grid.Children.Add(this.player);
this.player.Visibility = Visibility.Collapsed;
this.player.MediaOpened += MediaOpened;
this.player.MediaEnded += MediaEnded;
this.player.MediaFailed += MediaFailed;
}
}
}

this.player = Application.Current.Resources["PhoneGapMediaPlayer"] as MediaElement;

this.player.MediaOpened += MediaOpened;
this.player.MediaEnded += MediaEnded;
this.player.MediaFailed += MediaFailed;

}
this.audioFile = filePath;
this.player.AutoPlay = false;

Uri uri = new Uri(filePath, UriKind.RelativeOrAbsolute);
if (uri.IsAbsoluteUri)
{
Expand Down
2 changes: 0 additions & 2 deletions framework/PhoneGap/Commands/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ public void activityStart(string unused)
var t1 = Application.Current.RootVisual;
PhoneApplicationFrame frame = t1 as PhoneApplicationFrame;

var temp1 = frame.FindName("LayoutRoot");

if (frame != null)
{
PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
Expand Down

0 comments on commit d34f29b

Please sign in to comment.