Trying to play sound effects using XNA - windows-phone-7

I'm writing my first app for windows phone, which will be a sound board, using XNa's soundeffect object.
The project is a Windows phone Silverlight and Xna Application c#
I got some sample code from the book, 101 phone 7 apps.
The linbe to load in the sound gives me a
"the type StreamResourceInfo namespace could not be found"
StreamResourceInfo info = Application.GetResourceStream(new Uri("Audio/cowbell.wav", UriKind.Relative));
the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework.Audio;
namespace SlXnaApp4
{
public partial class MainPage : PhoneApplicationPage
{
SoundEffect cowbell;
// Constructor
public MainPage()
{
// Load sound file
StreamResourceInfo info = Application.GetResourceStream(new Uri("Audio/cowbell.wav", UriKind.Relative));
// create xna sound
cowbell = SoundEffect.FromStream(info);
// Sub to per frame call back
CompositionTarget.Rendering += CompositionTarget_Rendering;
// requred for xna sound effects to work
Microsoft.Xna.Framework.FrameworkDispatcher.Update();
// testb sound
cowbell.Play();
InitializeComponent();
}
void CompositionTarget_Rendering(object sender, EventArgs e)
{
Microsoft.Xna.Framework.FrameworkDispatcher.Update();
}
// Simple button Click event handler to take us to the second page
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
}
private void button1_Click(object sender, RoutedEventArgs e)
{
}
}
}

Add a using directive for System.Windows.Resources:
using System.Windows.Resources;

Related

Download Manager in Xamarin results in "Unsuccessful Download" notification on smartphone, with no exception thrown

I can download some files in a random page (a pdf from google, for example) but in the page I need to download them from, I get "Unsuccessful Download" notification on smartphone, with no exception thrown for me. Is there a way to know why this is happening?
Code from the renderer that I use to download below.
using Android.App;
using Android.Webkit;
using MPS.Libertas.Mobile.Droid.Renderers;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using Android.Content;
using Xamarin.Essentials;
using System.IO;
using System;
using Android.Widget;
using static Android.Provider.MediaStore;
[assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(MPS_MyWebViewRenderer))]
namespace MPS.Libertas.Mobile.Droid.Renderers
{
internal class MPS_MyWebViewRenderer : WebViewRenderer
{
public MPS_MyWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
Control.Download += OnDownloadStart;
}
private void OnDownloadStart(object sender, Android.Webkit.DownloadEventArgs e)
{
try
{
var url = e.Url;
string url_formatted = url.Replace("blob:", "");
DownloadManager.Request request = new DownloadManager.Request(Android.Net.Uri.Parse(url_formatted));
request.AllowScanningByMediaScanner();
request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
request.SetMimeType("application/pdf");
                // if this path is not create, we can create it.
                string thmblibrary = FileSystem.AppDataDirectory + "/download";
if (!Directory.Exists(thmblibrary))
Directory.CreateDirectory(thmblibrary);
request.SetDestinationInExternalFilesDir(Android.App.Application.Context, FileSystem.AppDataDirectory, "download");
DownloadManager dm = (DownloadManager)Android.App.Application.Context.GetSystemService(Android.App.Application.DownloadService);
dm.Enqueue(request);
}
catch (System.Exception ex)
{
var message = ex.Message;
throw;
}
}
}
}

Execution of infinite loop in c exe vs c# exe

I created a c program which has infinite loop.It runs fine.I also created c# program which has infinite loop.While the form ran,latter program process stopped responding.Why does both behaves differently?
Below are the codes
#include<stdio.h>
int main()
{
int i;
for(i=0;i>=10;i++){
printf("%d",i);
}
return 0;
}
c# program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i=10;
while (i > 1)
{
//do nothing
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
My question is how infinite loops work in these two programs?
Your C# program is in a form. Windows expects the form to be able to process events (e.g. telling it to close) but it can't because it's in the infinite loop.
If the infinite loop was in its own thread, or you wrote a C# console application instead of a form-based one, I think it would behave more like your C.

name 'application' does not exist in the current context

Hi I'm working to develop a solution to creating a toolbar in Outlook 2010 using VSTO 2012 and the microsoft outlook 2010 addin. In a nutshell I am able to create the Outlook ribbon and a button but I am unable to get the button to open an .oft file. In Visual Studio I get the following error "The name 'application' does not exist in the current context". I have added a reference to the Microsoft Office 14.0 Object Library also. Below is the code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Ribbon;
namespace OutlookAddIn8
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void CreateItemFromTemplate()
{
Outlook.Folder folder =
Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
#"c:\ivy.oft", folder) as Outlook.MailItem;
mail.Subject = "Congratulations";
mail.Save();
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
}
}
}
Thanks any help is appreciated it is probably something simple thats been missed.
An instance of Application can be accessed using Globals.ThisAddIn.Application. If you renamed your AddIn class to something different e.g. MyAddIn then the command will be: Globals.MyAddIn.Application.
Here is a link with more details: http://msdn.microsoft.com/en-us/library/vstudio/bb157876(v=vs.100).aspx
Finally got there in the end, heres the code.....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookAddIn3
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application Application = Globals.ThisAddIn.Application;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
#"Z:\Transfer\Outlook 2010 Templates\testsubject.oft") as Outlook.MailItem;
mail.Display(true);
}

Tilting web browser on windows phone 7

i'm working on a windows phone 7 emulator. I have a web browser which navigates to local host. So my problem i faced was that when i tilt the windows phone 7 emulator 90% right, the screen doesn't. Could there be any advice on how to do so?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace DSP
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show("Loading website. This might take a few seconds...");
webBrowser1.Navigate(new Uri("http://localhost/Liweiyi_fyp_082648y/homepage.html", UriKind.Absolute));
}
private void webBrowser1_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
Check your SupportedOrientations is PortraitOrLandscape in your xaml.
Also check your emulator isn't orientation locked due to hardware keybaord emulation. Restart it if you're not sure how to fix that.
I believe you're looking for how to handle orientation changes on the phone?
You're looking to change the following in the .xaml for the appropriate page - most likely MainPage.xaml:
Change the highlighted line to read
SupportedOrientations="PortraitOrLandscape"
And in case that wasn't enough information, here's a helpful blogpost.

Cocoa: PhotoshopImage class and resize

Does anyone knows how i can resize the PhotoshopImage instance?
I don't us the UIImageView because i need to load a lot of images and the PhotoshopImage class handles it better.
Got a real shaky start for you! Photoshop has documentation on using javascript vbscript with photoshop dll's: http://www.adobe.com/devnet/photoshop/scripting.html. These same methods are exposed via COM to C# and I wonder if they're available to Objective-C (RedGate and the vs object browser can help if you dabble with it). Don't cringe at the C# code! The point is photoshop exposes dlls which can be worked with. C# ASP.NET exposes photoshop .dll's via COM. I'm new to objective-c and not a vet at C#! I got this code to work on my windows machine in C#. This code cranks up a web page and fires up my version of photoshop cs3 and goes thru my directory of files and creates an "Adobe image gallery". Good luck to you and post back what you find in objective-c...I think objective-c can run native C and I've seen some documentation of working with photoshop in native C...Shoot some code back either way...I'm a semi newbie so if this wasn't what you meant by Photoshop Image I apologize!
CDUB
PS these are all photoshop methods being exposed, nothing I made up...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GoogleTalkAPILib;
using ps = Photoshop;
using Photoshop;
namespace photoshop
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
Object ob= null;
//works!!!!!!
// co.Application.MakePDFPresentation(oaa,
"C:\Users\Photoshoptryrescl",ob);
//you can also use c# to run a javascript
// co.DoJavaScript("hey.js",e,d );
co.MakePhotoGallery(oab, "C:\\photoshopdump", ob);
}
catch (Exception ex)
{ Trace.Write(ex.Message.ToString()); }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ps = Photoshop;
using Photoshop;
using Microsoft.Win32.SafeHandles;
using Microsoft.Win32;
using Microsoft;
namespace photoshop
{
public delegate void addBlur();
public class Class1 : ApplicationClass, ArtLayer, Document
{
public Class1()
{ }
public void addBlur()
{ }
public void addBlur1(string sa)
{ }
#region ArtLayer Members
public void AdjustBrightnessContrast(int Brightness, int Contrast)
{
throw new NotImplementedException();
}
public void AdjustColorBalance(object Shadows, object Midtones, object Highlights, object PreserveLuminosity)
{
throw new NotImplementedException();
}
public void AdjustCurves(object CurveShape)
{
throw new NotImplementedException();
}
public void AdjustLevels(int InputRangeStart, int InputRangeEnd, double InputRangeGamma, int OutputRangeStart, int OutputRangeEnd)
{
throw new NotImplementedException();
}
public bool AllLocked
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public void ApplyAddNoise(double Amount, PsNoiseDistribution Distribution, bool Monochromatic)
{
throw new NotImplementedException();
}
public void ApplyAverage()
{
throw new NotImplementedException();
}
public void ApplyBlur()
{
// throw new NotImplementedException();
}
public void ApplyBlurMore()
{
throw new NotImplementedException();
}
//etc... these interfaces expose a ton of methods which can be explicity implemented
//this isn't them all

Resources