I'm using a MediaPlayerLauncher to show movietrailers in my WP7 application, like this:
MediaPlayerLauncher mpl = new MediaPlayerLauncher();
mpl.Media = new Uri(trailerUrl, UriKind.Absolute);
mpl.Controls = MediaPlaybackControls.All;
mpl.Show();
This works just fine, except one thing: if the user is already listening to music in the background, and launch a trailer, the music is not resumed after the trailer is done playing (or if the user closes the video).
Does anyone know how i can resume the previously playing music/media, if even possible?
Local media playing through XNA or a 'background audio agent'?
When you play media in WP7 / WP8, the OS audio context is taken, and the original context is lost. If the audio was launched from an external application, then you cannot resume at all. If the previous media was launched from within your application, then you could store the meta-data and re-play once your trailer is finished. The media would, of course, then begin playing from the start, rather than where the user left off. Unfortunately XNA does not allow you to seek within a given piece of media; however you can seek within an 'audio agent' instance of 'BackgroundAudioPlayer' by setting player.Position. It's also worth looking at the MediaHistory API:
var nowPlaying = Microsoft.Devices.MediaHistory.Instance.NowPlaying;
Figured it out. Calling MediaPlayer.Resume() right after show() solves the issue:
mpl.Media = new Uri(trailerurl, UriKind.Absolute);
mpl.Controls = MediaPlaybackControls.All;
mpl.Show();
MediaPlayer.Resume();
However, i would still like to know how to resume radio and spotify!
Related
An alternative title could be: What happened to PIN_CATEGORY_STILL?
I am currently comparing images that were captured using DirectShow and PIN_CATEGORY_STILL with images that were captured using UWP MediaCapture.
On the device I am testing/playing around with DirectShow and MediaCapture, DirectShow detects a PIN_CATEGORY_STILL but I am not able to initialize an instance of MediaCapture with anything other than PhotoCaptureSource.VideoPreview.
MediaCaptureInitializationSettings settings = new()
{
VideoDeviceId = someDeviceId,
PhotoCaptureSource = PhotoCaptureSource.Photo
};
MediaCapture capture = new();
// this throws an exception
// "The capture source does not have an independent photo stream."
await capture.InitializeAsync(settings);
At this point I'm not even sure if PhotoCaptureSource.Photo is meant to be used as an equivalent to PIN_CATEGORY_STILL.
Images captured with PIN_CATEGORY_STILL are way brighter in a dark environment and have a much better quality (in file size and resolution) (which is clear to me, since I am using PhotoCaptureSource.VideoPreview for MediaCapture).
Considering this resource Win32 and COM for UWP apps, it seems like UWP MediaCapture does not use DirectShow underneath but MediaFoundation (which is meant to be a successor for DirectShow).
This article led me to this StackOverflow question Media Foundation is incorrectly marking still image capture stream descriptors as video capture, which basically states that MediaFoundation has no PIN_CATEGORY_STILL but returns 1 FPS as video capability for such devices (or profiles).
Since I am not directly using MediaFoundation nor C++, I tried testing this by querying GetAvailableMediaStreamProperties:
private void Foo()
{
var videoPreviewProperties = GetEncodingProperties(MediaStreamType.VideoRecord);
var photoProperties = GetEncodingProperties(MediaStreamType.Photo);
var videoRecordProperties = GetEncodingProperties(MediaStreamType.VideoPreview);
}
private List<VideoEncodingProperties> GetEncodingProperties(MediaStreamType streamType)
{
// MediaCapture was previously initialized with PhotoCaptureSource.VideoPreview
return MediaCapture.VideoDeviceController
.GetAvailableMediaStreamProperties(streamType)
.OfType<VideoEncodingProperties>()
.ToList();
}
None of these returns a VideoEncodingProperties with only 1 FPS.
To test MediaCapture any further I tried some of the sample applications from here UWP sample. I tried CameraAdvancedCapture, CameraOpenCV and CameraManualControls, but the results were not nearly as good as good old PIN_CATEGORY_STILL.
What happened to PIN_CATEGORY_STILL?
Is there any way to capture images without DirectShow/PIN_CATEGORY_STILL and still keeping this level of quality?
Any enlightenment is much appricated.
I'm trying to play a HDHomeRun Connect Video source from a url in the following format: http://x.x.x.x:xxxx/auto/v4.1. This video source is an MPEG2 video encoding and AC3 audio encoding.
I've tried using the Samsung Tizen.TV .NET sample with the following source but the video never plays.
_player = new Tizen.Multimedia.Player();
var mediaSource = new Multimedia.MediaUriSource(uri);
_player.SetSource(mediaSource);
var display = new Multimedia.Display(Window.Instance);
_player.Display = display;
await _player.PrepareAsync();
The player state gets stuck in preparing, and the await _player.PrepareAsync() call never finishes. It is worth noting that I'm using the Tizen Samsung TV Emulator. Do I need to transcode the stream from the HDHomeRun to be playable? Are there any other measures I might be missing for the Video to play?
Ultimately, the Display property of the player wasn't being set correctly. The property that worked for me (found from investigating the JuvoPlayer code was this:
var display = new Multimedia.Display(((FormsApplication)Forms.Context).MainWindow);
_player.Display = display;
When you are to develop a Tizen .NET application, please be aware of which UI framework your project is targetted for among 3 different types: Xamarin.Forms, (pure) ElmSharp, and Tizen.NUI.
Unless your project is based on the Tizen.NUI framework, you shouldn't use Tizen.NUI.Window.Instance and types in Tizen.NUI namespace in any case. Instead, you will have to use types of ElmSharp or Xamarin.Forms.Platform.Tizen namespace for platform-specific code in your application.
Since the internal implementation of Xamarin.Forms for Tizen is based on ElmSharp, FormsApplication.MainWindow will return a ElmSharp.Window instance which can be used to instantiate a Tizen.Multimedia.Display object. That's why the code in your answer worked.
I have been using the code in http://opensebj.blogspot.com/2009/04/naudio-tutorial-5-recording-audio.html to record audio. Basically this code:
WaveIn waveInStream;
WaveFileWriter writer;
waveInStream = new WaveIn(44100,2);
writer = new WaveFileWriter(outputFilename, waveInStream.WaveFormat);
waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
waveInStream.StartRecording();
It works perfectly and record every sound on the system. The problem arises when I pluck in a headset (not usb, just directly into the headset jack on the built in soundcard on my laptop). This has the effect that any sound I can hear in the headset is not recorded.
I think it has something to do with which device i am recording from, but I can't quite figure it out.
I am trying to record a conversation, which means I would like to record the sound that comes from the mic and the sound I can hear in the headset at the same time.
Can someone point me in the right direction for this? Thanks.
// Get default capturer
waveInStream = new WaveIn(44100,2);
Now if you plug in your headset microphone/speaker then Windows will detect it but your program is still using the old 'default' endpoint. Not the lastly added device. This needs to be updated.
One of the solution would be to poll the endpoints and see if any new (default) device has been added to the system and then stop-start the recording with the new device.
waveInStream.StopRecording();
// assign the default recording device if not already done
//waveInStream.DeviceNumber = 0;
waveInStream.StartRecording();
Let me know if I was not very clear in the explanation.
I'm working on a simple mp3 player project with C# and the WMPLib library. The idea is to make it controllable with a PIC component, to control media playing in the PC from "anywhere" in my house (yes, this is a college project).
The problem: I can't get the WindowsMediaPlayer.controls.play() method to resume a paused playback. How should I do it?
I've already tried to save and set the WindowsMediaPlayer.controls.currentPosition property, but it doesn't work.
PS:
The same problem: http://social.msdn.microsoft.com/Forums/en-US/windowspro-audiodevelopment/thread/770d22fc-7ef1-475e-a699-b60e2282a7c7/
Different problem: pause and resume Windows Media Player in C#
Thanks in advance
EDIT: WindowsMediaPlayer.controls.currentPosition works fo setting the position, but not for getting it:
double time = Player.controls.currentPosition; //Returns 0 always
Player.controls.currentPosition = time; //Works fine, makes music jump to time seconds
...
double time = Player.controls.currentPosition; //return always 0 for you, because you pause first and after get the value
Player.controls.pause();
Player.controls.currentPosition = time;
Player.controls.play();
You can get currentposition by converting it to string for example:
label1.text = convert.tostring(Player.controls.currentPosition);
I've used a label to show you the exactly currentPosition value.
Regards
I'm using a COM Wrapper to interact with Windows Media Player.
The it is using an AxHost to somehow wrap the player, for me it's all just magic under the hood^^
The AxHost.AttachInterfaces looks like this
protected override void AttachInterfaces()
{
try
{
//Get the IOleObject for Windows Media Player.
IOleObject oleObject = this.GetOcx() as IOleObject;
//Set the Client Site for the WMP control.
oleObject.SetClientSite(this as IOleClientSite);
Player = this.GetOcx() as WMPLib.WindowsMediaPlayer;
...
Everything is working find as long as I host this AxHost in a Windows Forms control. But I can't hook up the events in a constructor.
This for example doesn't work:
public WMPMediaRating()
{
var remote = new WMPRemote.RemotedWindowsMediaPlayer();
_WMP = remote.Player;
_WMP.MediaChange += new _WMPOCXEvents_MediaChangeEventHandler(_WMP_MediaChange);
}
remote.Player is always null and the program crashes with a NullReferencesException.
The code in AttachInterfaces() is somehow only executed after the Form has been drawn, or after everything else is done.
I tried calling AttachInterfaces() by hand, but that didn't work either because GetOcx() returns nothing.
So how can I instantiate my AxHost-inherited control without Windows Forms, to use it for example in a console application?
FYI: nobody stops you from using a hidden window in your console application.
You'll not be able to host the media player in a non-windows application - it requires hosting. If you want to play some music you can use the Media Graphs to create a graph that renders (plays) your music file - it'll not require any extra hosting.