How can I start QuickTime and have it start playing a url? - cocoa

I'm using MonoMac, but I understand cocoa and objc well enough that if you can answer me in those languages, please do.
I have a url from my web server which returns an mp4. I'd like my MonoMac application to launch QuickTime and start playing that url.
I tried these methods:
Process.Start("/Applications/QuickTime Player.app/Contents/MacOS/QuickTime Player", url);
but when the url is something like http://webhost/1/blah.mp4, quicktime says "The document blah.mp4 could not be opened. The file doesn't exist. I know the file exists and everything is correct. If I use this method:
var cfurl = MonoMac.CoreFoundataion.CFUrl.FromUrlString(url, null);
LSOpenCFURLRef(cfurl.Handle, (IntPtr)null);
The stream is opened in Safari and the QuickTime plugin starts playing it.
I've also tried NSWorkspace OpenUrls and OpenFile
NSWorkspace.SharedWorkspace.OpenUrls(new[]{NSUrl.FromString(url)},
#"com.apple.quicktimeplayer",
NSWorkspaceLaunchOptions.Async,
new NSAppleEventDescriptor(),
new[]{""});
but this launches in safari
NSWorkspace.SharedWorkspace.OpenFile(url, "QuickTimePlayer");
but this does nothing.
So I try NSTask
MonoMac.Foundation.NSTask.LaunchFromPath("/Applications/QuickTime Player.app/Contents/MacOS/QuickTime Player",
new string[] {url});
But this gives the same "... could not be found..." as my very first attempt above.
Finally, if I start QuickTime Player and use open URL and paste the url into the textbox and click Open, the stream plays without error.
How can my cocoa app send a URL to QuickTime Player?

Considering the URL is a remote URL, you can use Scripting Bridge in Cocoa applications to ask QuickTime Player to open a remote URL:
id qtApp = [SBApplication applicationWithBundleIdentifier:#"com.apple.QuickTimePlayerX"];
[qtApp activate];
if ([qtApp isRunning]) {
// note that the parameter to openURL: must be the string representation of a URL
[qtApp openURL:#"http://movies.apple.com/media/us/ipad/2011/tours/apple-ipad2-feature-us-20110302_r848-9cie.mov?width=848&height=480"];
}
You’ll need to link the Scripting Bridge framework to your application.

Related

Opening the uri from background tasks in Universal windows apps

I know this sounds weird. Is there any way we can open a URI from background tasks in Windows 10 Apps?
I have 2 requirements,
Talk to cortana and it will show you results based on the speech recognition, when user clicks on it, we cannot open the links in browser directly. Instead I am passing the Launch Context to the Foreground app and then using LauchUri I am opening the url in default browser.
Send toast notifications from the App, when user clicks on it, I have requirement to open a url instead opening an app. So, did the same, by passing the launch context to foreground app and then opening the url.
Both scenarios, it just opening url in browser. Here user experience is very poor that user seeing the app open for each action and then opening browser. Please throw some ideas if any possibilities.
thanks in advance.
For your second requirement, you can make Toast Notifications launch a URL!
If you're using the Notifications library (the NuGet package that we suggest you use), just set the Launch property to be a URL, and change the ActivationType to Protocol. You can also do this with raw XML, but that's error-prone.
You can also make buttons on the toast launch a URL too, since they also support ActivationType of Protocol.
Show(new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText() { Text = "See the news" },
new AdaptiveText() { Text = "Lots of great stories" }
}
}
},
Launch = "http://msn.com",
ActivationType = ToastActivationType.Protocol
});

Windows Phone leave background music playing

My Windows Phone app was rejected because when I play a sound in the browser in my app it stops existing background music from playing (rejection issue 6.5.1).
How do I update my application to not stop background music?
My JavaScript is something like this:
var mySound = new Audio(soundpath);
Sound.play(mySound);
I could not find anything in Microsoft.Xna.Framework.Media that handles how the app handles browser sound, but maybe I missed something?
What you are looking for is from the xna soundeffect
Here is what I use and it works for me great for all my sound effects.
(You cannot use music with a 'soundeffect' object, as it will not pass the windows store qualifications. You have to use the MediaElement for music)
I can’t remember which you need but I have all these includes
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
and this function
private static void LoadSoundEffect(string fileName, SoundEffectInstance mySound)
{
var stream = TitleContainer.OpenStream("Sounds/" + fileName);
var effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
mySound = effect.CreateInstance();
}
If you use a SoundEffectInstance, you can start,pause,stop the soundeffect etc. without all the problems.
SoundEffect works as well, but I prefer the SoundEffectInstance.
Edit: If you use soundeffect, it will not effect the music being played.
I'm assuming that you are building a native Windows Phone app (.XAP) and then using a browser control to display your app content. If that is the case, you have checks that you will need to perform when the app is first opened. Below is a description of how to resolve that issue.
You will need to add this piece of code to your app (I suggest you check this every time your app loads/opens). Add a reference with the using statement as well for the Media.
if (Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Playing)
{
MessageBoxResult Choice;
Choice = MessageBox.Show("Media is currently playing, do you want to stop it?", "Stop Player", MessageBoxButton.OKCancel);
if (Choice == MessageBoxResult.OK)
mediaElement1.Play();
}
If the user allows or disallows the media to be played you must put checks in your JavaScript for this. You will fail certification again if the user says "Cancel" and you play music anyway.
There is more information on the topic here.

Extrading Metadata of an audio streaming file (MediaElement)

I just started to develop for the Windows Phone (7.1/8) platform and am still not really familiar with it.
My plan is an internet radio app which streams the audio file from a server. I used MediaElement to set the source property to the streaming URL.
It works and the app starts playing the music but I can't read any metadata about the song which is coming from the server such as artist name/title or any string which I can use to know about the song itself.
I've been searching around and tried the MediaReached event as well, but it never gets fired as well?
So any idea what should I do?
and My Code Behind Sample:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MyMedia.Source = new Uri("MyURL");
}
I hate to tell you this but it is because the MediaElement.Attributes are not supported for Windows Phone 7 - all the limitations can be found here: http://msdn.microsoft.com/en-us/library/ff426928(VS.95).aspx

MediaPlayerLauncher with HTTPS

I would like to open an audio file from an HTTPS resource.
First, I tried using MediaPlayerLauncher like so:
MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher {
Media = filename,
Controls = MediaPlaybackControls.Pause,
Orientation = MediaPlayerOrientation.Portrait,
Location = MediaLocationType.None
};
mediaPlayerLauncher.Show();
filename in this case is a URL beginning with https://.
Using Fiddler to monitor traffic, I have noticed that https:// in filename is getting changed to http://.
Next I tried opening the same URL using WebBrowserTask:
WebBrowserTask webBrowser = new WebBrowserTask {
Uri = filename
};
webBrowser.Show();
Checking Fiddler out again, I noticed that two requests are being sent. First is a request to filename by the browser. This results in the "Tap to open file" message to appear in the browser. Tapping it opens the phone's media player (MediaPlayerLauncher?), which sends another request -- in this case, the https:// changed to http:// again (which is similar result to first attempt).
The server I am getting the file from only supports HTTPS, hence the problems arising when the media player requests the file as HTTP.
Is there anyway to stream a file from an HTTPS resource? Does Windows Phone's media player even support it?
Pointing location on the internet for the MediaLuncher is a bad idea. It will freez UI thread and your app won't be responsive. Try first download the audio as a stream and then play it. Use WebClient to open a stream. HTTPS can be open in WP7, so that shouldn't be a problem.

How to access local media file on my computer in JavaFX?

How to access local media file on my computer in JavaFX?
Here are the urls I tried:
C:/PROJECT/videos/on2tm_352.flv
file:///C://PROJECT/videos/on2tm_352.flv (suggested in some site forgot where)
It does play however, when I put the media file inside the project's folder and access it using {__DIR__}/on2tm_352.flv
Note: There are no exceptions and errors outputted. The screen is just blank.
KLite Codec 583 Mega, JavaFX 1.2, Netbeans 6.8 are used
It is working right now for me:
private static final String MEDIA_URL = "file:/c:/Users/Alejandro/Downloads/oow2010-2.flv";
I tested it a few minutes ago....
or something like that:
private File file = new File("c:/Users/Alejandro/Downloads/oow2010-2.flv");
private final String MEDIA_URL = file.toURI().toString();
See you later =D
Try this out:
Media media = new Media(trackFile.toURI().toURL().toString());
MediaPlayer mediaPlayer = new MediaPlayer(media);
By giving their URL to the Media?
Note that some issues with spaces in paths have been reported in the past, I don't know if it is still true.
[EDIT following original message edit (URL examples)]
First line isn't an URL, it is a path. Apparently the media player accepts paths as URL, but that's not the case for ImageView, though, so it is better to be strict.
Second line is correct.
Third line have a potential issue: __DIR__ variables has already a terminal slash, so you should not add it, ie. write {__DIR__}on2tm_352.flv instead. Not sure if that's the issue (I haven't used much video yet) but worth trying.
Note that such URL (based on __DIR__) will point inside a jar file once the project is packaged.
It is OK in JavaFX 1.2, but for some odd reason, they chose to disallow such access in 1.3.
I have found it easier to do the following with disk files. This relieves my feeble brain of determining all the rules for "file:" urls:
var file = new File("C:/PROJECT/videos/on2tm_352.flv");
Media {
source: "{file.toURI()}"
}
I avoid using {__DIR__} for media as it can point to a "jar:" URL and that is no longer supported for media locations in JavaFX 1.3.
You guys just have to specify the file's path as an URI path:
Media media = new Media("file:///C:/Users/David/Downloads/test.flv");
MediaPlayer mediaPlayer = new MediaPlayer(media);
It's not required to instantiate a File at all.

Resources