I am using windows media player in windows forms application. I have 10 media items in my playlist. foo, foo1,foo2,foo3 ....
Now my playlist is playing lets say foo1. Now on button click I want to play item foo6. How do I play this ? i.e. how do I change my current playing item too foo6 ?
If this is not clear please comment, I will add more information.
Edit: Following is the code for creating a new playlist.
WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass();
playlist = WMPLeft.playlistCollection.newPlaylist("myplaylist1");
for (int i = 0; i < FOO.Length; i++)
{
media = WMPLeft.newMedia(FOO[i]);
playlist.appendItem(media);
}
What I want is something like this
WMPLeft.playlist.Item(3).play();
This is wrong. But this is the kind of code I want.
After much research I have found this msdn link which shows how to do what I wanted.
// Declare a variable to hold the position of the media item
// in the current playlist. An arbitrary value is supplied here.
int index = 3;
// Get the media item at the fourth position in the current playlist.
WMPLib.IWMPMedia media = player.currentPlaylist.get_Item(index);
// Play the media item.
player.Ctlcontrols.playItem(media);
LINK to MSDN
Related
I have an application in which I have a requirement to take multiple images in one shot by phone camera. User don't want to open camera again and again.
I have tried https://github.com/jamesmontemagno/MediaPlugin Plugin also but it do not support continuous Images capturing. It clicks one image at a time.
Is there a way to achieve this behaviour?
Thanks
Can you try this in media plugin
for (int i = 0; i < 3; i++)
{
file = await MediaPicker.TakePhotoAsync(new StoreCameraMediaOptions { SaveToAlbum = true, Name = "", Directory = "" });
if (file != null)
{
//code to save
}
The user can press cancel at anytime to stop taking pictures, and it'll hit the return and stop running the code. But its ran the logic to save the images each time a photo has been taken.
In my project i have two combobox that showing the list of available video devices and audio devices. i want to set a default video device to capture the image.
In my code
var vidDevices = EncoderDevices.FindDevices(EncoderDeviceType.Video);
var audDevices = EncoderDevices.FindDevices(EncoderDeviceType.Audio);
by default it shows "Screen Capture Source" but i want to show the list of available devices.
after you have passed this line :
var vidDevices = EncoderDevices.FindDevices(EncoderDeviceType.Video);
vidDevices will contain en enumerable with all available devices in it.
In WPF, you can simply pass this into the combobox as an itemssource like this :
combobox.itemsSource = vidDevices;
Then, in order to get the one the user selected, take the SelectionChanged event of the combobox and do something like this :
var selectedDevice = comboBox.SelectedItem as EncoderDevice;
I have a track which is playing on my phone and then I pause it using the controls that pop down after pressing the volume keys.
In my application, how can I resume that song and find out what the song is?
The following does not work.
MediaPlayer.Queue.ActiveSong // This reports no songs at all. Only works if I give it a song to play
MediaHistory.Instance.NowPlaying.Title // MediaHistory.Instance = null
Also just trying this does nothing.
MediaPlayer.Resume
Edit: If it makes any difference, I am debugging a Windows Phone 7 app on and Windows Phone 8 device.
If I give a song to MediaPlayer to play then all the above works.
to play a song
MediaPlayer.Play(SongCollection songs);
MediaPlayer.Play(SongCollection songs,int index);
and to get songs
MediaLibrary mLibrary = new MediaLibrary();
songs = mLibrary.Songs;
to check current state
if(MediaPlayer.State == MediaState.Playing || MediaPlayer.State == MediaState.Paused)
and to check active song
Microsoft.Xna.Framework.Media.MediaPlayer.Queue.ActiveSong.Name;
I am using C1MediaPlayer WPF Control. Now i got a problem in displaying the Media's Duration in Player's Playlist,
C1MediaItem MediaClip = new C1MediaItem();
MediaClip.MediaSource = new Uri(MediaPath);
MediaClip.Title = title;
MediaPlayerControl.Items.Add(MediaClip);
When i open the Playlist, my item's Duration is "00:00:00".
I want to set my item's Duration to it's full length not "00:00:00", Please help me?
You can set the NaturalDuration property to the length of the video.
To do this, right click on the C1MediaPlayer and select Properties. Scroll down to 'Items' collection and click on ellipses. Select the mediaItem from the left pane, and set the NaturalDuration on the right pane. Or you can just set the property in XAML thus:
NaturalDuration="00:28:15"
I've also posted a sample app at this link for your reference.
I am using VSTS 2008 with C# to develop Silverlight application embedded in web page of an ASP.Net web application. I have embedded in XAML a MediaElement item. My question is, I want to embed the page a Silverlight media player, which could let end user to control the MediaElement item manually to -- play/pause/stop/rewind/forward. Are there any references samples?
thanks in advance,
George
EDIT1: add more accurate requirements,
Actually, I want to control play manually, which means I want to handle the player play/pause/stop/rewind/forward events and add my code for the event handlers to control the MediaElement and do something else.
EDIT2: My needs are, I want to play two overlapped video. Screen as background video and camera as foreground video (place at right bottom corner). Here is my modification of code, my current issue is, only background video is played, foreground right bottom video is never played. Does anyone have any ideas why?
BTW: my modified code and current work is based on http://www.codeplex.com/sl2videoplayer
http://www.yourfilehost.com/media.php?cat=other&file=sl2videoplayer_24325_new.zip
Here is a brief description of my major modified code,
mediaControls.xaml.cs
private MediaElement _media = null;
private MediaElement _camera = null;
public MediaElement Camera
{
set
{
_camera = value;
}
}
void btnPlay_Checked(object sender, RoutedEventArgs e)
{
_camera.Play();
_media.Play();
OnPlayClicked();
}
Page.xaml
<MediaElement HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="mediaPlayer" Stretch="Uniform" VerticalAlignment="Stretch" AutoPlay="false"/>
<MediaElement Width="100" Height="100" x:Name="cameraPlayer" AutoPlay="false" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
Page.xaml.cs
cameraPlayer.Source = App.Current.Resources["c"] as Uri;
App.xaml.cs (Application_Startup function)
else if (item.Key.ToLower() == "c")
{
FormatUri(e.InitParams["c"].ToString(), "c", false);
}
default.html
<param name="initParams" value="cc=true,markers=true,markerpath=markers_movie21.xml,m=http://localhost/screen.wmv,c=http://localhost/camera.wmv" />
Oh baby have I got the media player for you: Sl2 Video Player. MSPL open sourced and awesome.
To add the ability to control the player pragmatically, add ScriptableMembers.
You'll see the registration statement already in the code:
HtmlPage.RegisterScriptableObject("Page", page);
Now look at an example ScriptableMember:
[ScriptableMember]
public void SeekPlayback(string time)
{
TimeSpan tsTime = TimeSpan.Parse(time);
mediaControls.Seek(tsTime);
}
already exists in the code. Add more methods to do what you want to have happen. Then you can call the methods from managed code in another SL player:
HtmlElement videoPlugin = HtmlPage.Document.GetElementById("VideoPlayer");
if (videoPlugin != null)
{
ScriptObject mediaPlayer = (ScriptObject)((ScriptObject)videoPlugin.GetProperty("Content")).GetProperty("Page");
mediaPlayer.Invoke("SeekPlayback", TimeSpan.FromSeconds(seconds).ToString());
}
or from javascript:
var sl = document.getElementById("VideoPlayer");
var content = sl.Content.Page;
content.SeekPlayback('55');
If they are two seperate xap packages, there will be no way for the two to communicate since Silverlight sandboxes both individually.
SL2videoplayer says it supports streaming video. But when I try giving a media services broadcast url (OnDemand and Live) to init param 'm' nothing showed up. In the init param example page also a remote wmv file being played is shown.
Also are there any known issues of using this with SL 3?