|
|
Good day folks,
Is it possible to use WPF's media components to create an MP3 player? I would want the MP3 player to have the usual functions (i.e. list of songs, time elapsed/left, random/sequential play, loop, fast forward, etc... you get the picture). Also, I would also want the user to be able to add mp3 to it.
Any help or direction you can provide will be greatly appreciated. Also, if WPF's media component can't do it, are there any third party MP3 player's for WPF?
Thanks,
BP
|
|
|
|
|
There are 100's of example programs using the MediaElement control on the web. Many here on Code Project.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi All!
Somebody Please Help/Guide me to complete my module.
Tools Used
-----------
Asp.Net Server Control (Asp.Net 3.5)
Windows XP
Code Behind is visual basic
My Module
----------
I want to create a Button control. When it is clicked a function named GoNext() will be called and the definition of the GoNext() will be given in the code behind of the EndUser WebForm(i.e where the control is going to be used).
My Source Code is:
------------------
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace SfNextCmd
<defaultproperty("text"), toolboxdata(=""><{0}:sfnextcmd runat="server">")> _
Public MustInherit Class SfNextCmd
Inherits Button
Public MustOverride Function GoNext()
Private Sub SfNextCmd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
GoNext()
End Sub
End Class
End Namespace
Also if it is possible thro SilverLight Please send me the source code.
By Vijay
|
|
|
|
|
VijaySofist wrote: Also if it is possible thro SilverLight Please send me the source code.
Just calling a function on click event? It's possible to do in Silverlight. Just place a button on Page.xaml and subscribe the click event on constructor of Page.xaml.cs. Then, call the function..
If you are not familiar with Silverlight, please read this doc. http://www.silverlight.net/quickstarts/managed.aspx[^]
Hope it helps.
|
|
|
|
|
|
Hi Michael!
First of all thanks for the Reply yaar.
I was possible to Create a Button COntrol in SilverLight and able to Call a Function in the Click Event of that control. But it expects me to give the definition of that function Name in the same code behind window of the XAML.
What I want is just to call that function in the Click event and give that definition in the place where that Button Control is going to be used (i.e the end user code behind form). It must be Just like a MustOverride Function.
Thanks and Regards
Vijay. R
|
|
|
|
|
VijaySofist wrote: But it expects me to give the definition of that function Name in the same code behind window of the XAML.
I'm really not sure what you meant. There are only two things such as XAML file (e.g. Page.xaml) and code-behinded file (e.g. Page.xaml.cs )So, I'm not sure what you meant by "behind window of the XAML"
VijaySofist wrote: It must be Just like a MustOverride Function.
MustOverride used to use in base class and the property or method that use MustOverride need to be overridden in child class.
Are you talking about User Control Inheritance in Silverlight? If yes, there is one example about that in my blog.
|
|
|
|
|
Let me explain thro an example.
In Asp.Net when we create a New Project using Asp.Net Server Control, after the compilation of that project we can get a .dll File in the name of that project. We can use that .dll as a Control in any of the Separate ASP.Net project.
Like the same i am trying to make a Silverlight control.
What I meant by code behind is that aspx.vb (Separate Asp.Net Project page where that silverlight control is used)
Thanks and Regards
Vijay. R
|
|
|
|
|
Okay. Let me explain about Silverlight control and Silverlight Application.
Yes. You can create a ASP.NET control library and you can use it in any ASP.NET project.
The same goes for Silverlight. You can create a Silverlight control library and compile it as a .dll. then, you can use it in "Silverlight Application" (Not ASP.NET application.). So, the layout will be like that below.
-- ASP.NET WebSite
-----aspx (ASP.NET Page)
------xap (Silverlight 2 Application)
--------.dll (Siverlight 2 Control )
You can take a look at this sample[^] if you want to know how to use Silverlight control in Silverlight application and how to use SIlverlight application in ASP.NET.
Yes. All I'm talking about is Silverlight 2 beta1.
Hope it helps.
|
|
|
|
|
Hi,
I'm trying to get my mind around a problem I'm having with WPF. It can easily be compared to something like a stacked-bar chart (BTW, that's not what I'm creating, so please don't point me to a library providing these). Visually the results should look something like this:
NameA |-----||-----------||----|<br />
NameB |---------||-----------------|<br />
NameC |---||----------||-|
At the moment I have an Observable collection of data that provides me with two types, the string for the name and another collection with the values. I have used a ListView to display my table and the values are represented by an ItemsControl putting the data values inside a horizontally organized StackPanel .
<ListView ItemsSource="{Binding Source={StaticResource ResourceKey=data}}" Grid.Row="0" x:Name="myGrid">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
<GridViewColumn Header="Values">
<GridViewColumn.CellTemplate>
<DataTemplate>
<!-- Bind each item to the valueTemplate -->
<ItemsControl ItemsSource="{Binding Path=Values}"
ItemTemplate="{StaticResource valueTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView> The valueTemplate is implemented as this in the Windows.Resources block:
<DataTemplate x:Key="valueTemplate">
<Border Width="{Binding}" CornerRadius="2" >
<TextBlock Text="{Binding Title}" FontWeight="Bold" />
</Border>
</DataTemplate> Notice that the Width is, in the example above, set by a TypeConverter which takes an object of my datatype and returns a double corresponding to the width I want.
This works and the appearence is as desired. What I want to do now is make the "scale" of the displayed data change (not everything) e.g. if the value is 10, it is currently displayed as 10 pixels wide. I'd like to be able to adjust a slider to 2.0 and have the displayed data show as 20 pixels wide.
To attempt this, I've tried two main things:- Having my slider update a value that the
TypeConverter can see. When doing this, I can not seem to find any way to make the controls "redraw" using my new values. This also feels the wrong way to do things as the backend shouldn't need logic to affect the displayed output!
- Having the slider start animating the ScaleX element of a modified valueTemplate.
For the scaling, I've added the following to the valueTemplate
<Border.LayoutTransform>
<ScaleTransform x:Name="myScale" ScaleX="1.0" ScaleY="1.0" />
</Border.LayoutTransform> and a Slider like this:
<Slider x:Name="Scale" Width="100" Minimum="0.5" Maximum="10.0" Value="1.0">
<Slider.Triggers>
<EventTrigger RoutedEvent="Slider.ValueChanged">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="myScale"
Storyboard.TargetProperty="ScaleX"
To="{Binding ElementName=Scale,Path=Value}"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Slider.Triggers>
</Slider> The above code gives me an error 'myScale' name cannot be found in the name scope of 'System.Windows.Controls.Slider'. which makes some sense to me, but I can't see how to address the "name" defined inside of a template.
I've now hit a wall and don't know where to go next! Should I be defining a simple double in my resources and changing that? How can I define that (I assume I need to bring in some other namespace)? Can simple math be performed inside something like a Width field? Can anyone help me?
Regards,
Ray
|
|
|
|
|
Hi Ray,
Looks like your first problem is you need to have some sort of "shared" scale factor. You won't be able to access the element named 'myScale'. Since it's defined in a DataTemplate, there would be any number of elements with this name, so it would only be valid in the DataTemplate definition.
For the second problem, you say that you are using a TypeConverter, is that correct? If it is, then you will not be able to get the "values" refreshed automatically. Meaning you would have to refresh the bindings when the scale slider is moved.
What you can do is this:
1. Create a separate class (e.g. ScaleFactor) with a single property (e.g. Value)
2. Implement INotifyPropertyChanged in the ScaleFactor class and fire it when the Value changes.
3. Create an IMultiValueConverter that takes two values: 1st will be the "value" from your underlying data (you don't have to use a TypeConverter, but you probably can), 2nd will be the scale factor. The IMultiValueConverter will then multiply the two values and return that.
4. Define an instance of ScaleFactor in the Window's resource section.
5. Define an instance of your converter from #3 in the Window's resource section.
6. Update the Border's width to be a MultiBinding using your converter with the "value" and scale factor (from #4) as your input values.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Tom,
thanks for your reply. Your suggestions make a lot of sense and have, I feel, pointed me in the right direction. Although I think I'm messing up on step 6!
This is what I've done so far:
TJoe wrote: 1. Create a separate class (e.g. ScaleFactor) with a single property (e.g. Value)
2. Implement INotifyPropertyChanged in the ScaleFactor class and fire it when the Value changes.
public class VisualScale : INotifyPropertyChanged
{
private double scale = 1.0;
public double ScalingFactor
{
get { return scale; }
set { scale = value; NotifyPropertyChanged("Scale changed"); }
}
#region INotifyPropertyChanged Members
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
} TJoe wrote: 3. Create an IMultiValueConverter that takes two values: 1st will be the "value" from your underlying data (you don't have to use a TypeConverter, but you probably can), 2nd will be the scale factor. The IMultiValueConverter will then multiply the two values and return that.
public class WidthScaler : IMultiValueConverter
{
#region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ( targetType != typeof(double) )
{
throw new NotSupportedException("Target type of WidthScaler must be double");
}
if ( values.Length != 2 ||
values[0].GetType() != typeof(double) ||
values[1].GetType() != typeof(double) )
{
throw new NotSupportedException("Source values should be a pair of doubles");
}
return (double) values[0]*(double) values[1];
}
public object[] ConvertBack(object value,
Type[] targetTypes,
object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
} TJoe wrote: 4. Define an instance of ScaleFactor in the Window's resource section.
5. Define an instance of your converter from #3 in the Window's resource section.
<Window.Resources>
<local:Database x:Key="data" x:Name="data"/>
<local:VisualScale x:Key="scale" x:Name="scale" />
<local:WidthScaler x:Key="widthScaler" x:Name="widthScaler" /> TJoe wrote: 6. Update the Border's width to be a MultiBinding using your converter with the "value" and scale factor (from #4) as your input values.
<DataTemplate x:Key="programmeTemplate">
<Border>
<Border.Width>
<MultiBinding Converter="{StaticResource widthScaler}"
ConverterParameter="">
<Binding Path="{Binding Duration}" />
<Binding Path="widthScaler"/>
</MultiBinding>
</Border.Width>
I think I've either made the mistake in the bit above, or this bit...
<Slider x:Name="scaleSlider" Width="100" Minimum="0.5" Maximum="10.0" Value="{Binding Path=widthScaler}"/>
This is the exception I get is "A 'Binding' cannot be set on the 'Path' property of type 'Binding'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject. ". Whilst your reply has helped a lot, I've obviously not got the WPF gene kick in yet!
Regards,
Ray
|
|
|
|
|
I'm going to reply to myself as looking at the code I wrote I'd made an obvious mistake. Note, I still get the same exception but the following code is now used:
<Slider x:Name="scaleSlider" Width="100" Minimum="0.5" Maximum="10.0"
Value="{Binding ElementName=scale, Path=ScalingFactor}"/> and
<Border.Width>
<MultiBinding Converter="{StaticResource widthScaler}"
ConverterParameter="">
<Binding Path="{Binding Duration}" />
<Binding ElementName="scale" Path="ScalingFactor"/>
</MultiBinding>
</Border.Width> Hopefully this is now a little closer to the correct solution! Is it?
Regards,
Ray
|
|
|
|
|
Hi Ray,
Following the exception, this line is bad:
<Binding Path="{Binding Duration}" />
So here you are binding the Path property of a Binding object to the Value stored in the Duration property. You are basically double defining your binding statement. This needs to be:
<Binding Path="Duration" />
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Ok, that makes sense too.
When I run (or indeed the designer does the same). I've now got an exception being fired by the WidthScaler
if ( values.Length != 2 ||
values[0].GetType() != typeof(double) ||
values[1].GetType() != typeof(double) )
{
throw new NotSupportedException("Source values should be a pair of doubles");
} The debugger shows that the first value, Duration, is correct. But the second, is DependancyProperty.UnsetValue . If I remove the throwing of an exception and return null, the WidthScaler (the IMultiValueConverter) doesn't seem to be called again!
Regards,
Ray
|
|
|
|
|
Sorry, your second binding is incorrect also. You have:
<Binding ElementName="scale" Path="ScalingFactor"/>
But "scale" is not a named element, it is a resource. To access it, you need to set the Binding.Source property like so:
<Binding Source="{StaticResource scale}" Path="ScalingFactor"/>
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Great!
The application now runs, but moving the slider doesn't seem to result in the MultiBinding being called again (break-pointing doesn't stop the code).
Regards,
Ray
|
|
|
|
|
Did you update the binding there as well? It has the same problem as before. Make sure to look at the Output window of Visual Studio, that will have any binding errors listed.
Also, make sure the Binding for the slider has Mode=TwoWay.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I've now got this, but it still doesn't look like it works:
Xaml is now:
<Slider x:Name="scaleSlider" Width="100" Minimum="0.5" Maximum="10.0" Value="{Binding Source=scale, Path=ScalingFactor, Mode=TwoWay}"/>
I'd changed the binding in the MultiBinding to:
<Binding Source="{StaticResource scale}" Path="ScalingFactor"/>
Error in Output window is:
System.Windows.Data Error: 35 : BindingExpression path error: 'ScalingFactor' property not found on 'object' ''String' (HashCode=-528916476)'. BindingExpression:Path=ScalingFactor; DataItem='String' (HashCode=-528916476); target element is 'Slider' (Name='scaleSlider'); target property is 'Value' (type 'Double')
I'm sure the error will help, once I understand it!
Regards,
Ray
|
|
|
|
|
The two bindings you just posted are not the same. Compare them carefully (ignoring the fact that Mode is set on one of them though).
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Ok, given that they're both working on a source of "scale" and a Path of ScalingFactor (ignoring Mode), that leaves the fact that the second isn't a StaticResource. I'm not certain how to convert between the two markup conventions (although I guess I could expand out the Slider's "Value" element).
I tried this and it doesn't change anything
<Slider x:Name="scaleSlider" Width="100" Minimum="0.5" Maximum="10.0" Value="{Binding Source={StaticResource scale}, Path=ScalingFactor, Mode=TwoWay}"/>
Regards,
Ray
|
|
|
|
|
You still get the same binding error with that change?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Sorry, I noticed that you did not implement INotifyPropertyChanged correct. The parameter being passed needs to be the name of the property that changed, not some random text. Otherwise the system will never know where to look for the changed.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
PERFECT...
that was it.
Thanks a lot Tom, I felt I've learned a lot with your help! Thanks again!
Regards,
Ray
|
|
|
|