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
Related
In my app I need to measure a camera data if the glasses are moving or not. I get the data with:
quaternions["x"] = Camera.main.transform.rotation.x;
quaternions["y"] = Camera.main.transform.rotation.y;
quaternions["z"] = Camera.main.transform.rotation.z;
quaternions["w"] = Camera.main.transform.rotation.w;
quaternions["tx"] = Camera.main.transform.position.x;
quaternions["ty"] = Camera.main.transform.position.y;
quaternions["tz"] = Camera.main.transform.position.z;
If I move the glasses, the app works fine. But if I leave the glasses on the table, then after 4 minutes the glasses disable display and the code returns last stored data. Even if the charge cable is plugged in. If I press enable button on the glasses, the display is on again and the data is also right.
Is there some possibility to prevent the glasses falling asleep?
According to comment of #Kay, the solution is adding the line:
Screen.sleepTimeout = SleepTimeout.NeverSleep;
NOTE: this solution works if you use MixedRealityToolkit-Unity because it needs:
using UnityEngine;
You can adjust the sleep settings using the Device Portal under System->Preference.
When on battery, go to sleep after
When plugged in, go to sleep after
I have a c# windows form application and i want to playback video using embed vlc player and every thing is good.
But there is only one problem, however, that the quality of the video is dimmed, and the cloudy and opaque image is displayed.
i try change some properties like this:
VlcControl.Video.Adjustments.Contrast = 0;
VlcControl.Video.Adjustments.Brightness = 100;
VlcControl.Video.Adjustments.Gamma = 10;
VlcControl.Video.Adjustments.Saturation= 50;
But the image quality did not change. also i change VlcControl.Video.AspectRatio property.
How can i Enhance movie quality?
I ran into this problem and I determined that VLC seems to ignore these settings until the video actually starts playing. The workaround I came up with for my WinForm app was to start the video stream, and then repeatedly reapply the settings for awhile. I am sure there is a better way to do this, but for now, this gets the job done 100% of the time:
this.VlcControl.Play();
this.Show();
int counter = 0;
while (counter < 20)
{
Debug.WriteLine(this.VlcControl.State);
counter += 1;
Application.DoEvents();
Thread.Sleep(100);
this.VlcControl.Video.Adjustments.Enabled = true;
this.VlcControl.Video.Adjustments.Saturation = 1.35f;
}
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!
I'm writing an app to control an existing instance of WMP using C#.
Currently my code goes something like this:
private const int WM_COMMAND = 0x111;
private const int WMP9_PLAY = 0x4978;
SendMessage(WMP.MainWindowHandle, WM_COMMAND, WMP9_PLAY, 0);
This works fine for pausing media player, but if media player is paused or stopped, it skips to the next track. The command is called play, but I could have the wrong value for it. Does anyone either have a better value for WMP9_PLAY, or a better way to make WMP play?
By using Spy++ (from the answer above) I was able to find another set of SendMessage parameters that is sent when you press the play/pause on a windows keyboard that does the job:
SendMessage(WMP.MainWindowHandle, 0xC02B, 0x0000000C, 0x000E0000);
Check out the sample code here: Interoperating with Windows Media Player using P/Invoke and C#
When I try to stream sound from my microphone, I need to get it through a MediaStreamSource.
Therefore I first need to implement a MediaStreamSource for the pcm waveformat I get from my Microphone. There are at least two methods I think I need to implement. At first
protected override void OpenMediaAsync() {
// Create description
Dictionary<MediaStreamAttributeKeys, string> streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
streamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = output.CodecPrivateData;
audioDesc = new MediaStreamDescription(MediaStreamType.Audio, streamAttributes);
// register stream
Dictionary<MediaSourceAttributesKeys, string> sourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>();
List<MediaStreamDescription> availableStreams = new List<MediaStreamDescription>();
availableStreams.Add(audioDesc);
sourceAttributes[MediaSourceAttributesKeys.Duration] = TimeSpan.FromMinutes(0).Ticks.ToString(); // whatever I put here I get the same result.
sourceAttributes[MediaSourceAttributesKeys.CanSeek] = false.ToString();
ReportOpenMediaCompleted(sourceAttributes, availableStreams);
}
This works very well. My CodecPrivateData is '01000100401F0000803E0000020010000000' (PCM 1ch 16Bits 8kHz). This method gets called by setting the source as here:
WaveMediaStreamSource WaveStream = new WaveMediaStreamSource(output);
mediaElement.SetSource(WaveStream);
mediaElement.Play();
After Play() absoultely nothing happens. I would suggest the mediaElement should call at least once the method GetSampleAsync() of the MediaStreamSource. But it doesn't. I've noticed that the MediaElement doesn't make any call to the MediaStreamSource anymore.
While OpenMediaAsync the mediaElement.CurrentState is Opening. After that it turns to Playing but it doesn't play. And then it do not change anymore and remains Playing.
Any Ideas?
To get to the bottom of this you need to check MediaElement.CurrentState - it will tell you at which step of the interaction with the MediaStreamSource the MediaElement is stuck. This in turn will tell which of your MediaStreamSource methods should be impemented differently...
For a comprehensive walkthrough including essential information on the buffering part see http://msdn.microsoft.com/en-us/library/hh180779%28v=vs.95%29.aspx
Some things to try...
Try setting CanSeek to "0" and try a duration greater than zero, any hard coded value is fine to at least try to get it working. Also double check your CodecPrivateData string and make sure it's correct.
You also may want to try dropping in the Mp3MediaStreamSource from the ManagedMediaHelpers project and get that working first to make sure everything else in your app is set up properly then switch back to your custom MediaStreamSource.
When developing a mediaElement for Windows Phone (WP7.5 and WP8), for a reason that is completely beyond me, the debugger will not break on any breakpoints in the GetSampleAsync callback, the first time the callback is called !
The debugger will break the next time the breakpoint(s) will be reached. Try replacing your GetSampleAsync with this:
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
System.Diagnostics.Debug.WriteLine("Yay!");
MediaStreamSample msSamp = new MediaStreamSample(
_videoDesc, _frameStream, _frameStreamOffset,
_frameBufferSize, _currentTime, _emptySampleDict);
ReportGetSampleCompleted(msSamp);
}