locked
Seek bar issues RRS feed

  • Question

  • All,

    I am trying to create a Silverlight app with Blend which will allow the user to play multiple audio files at the same time (drums, bass guitar, rhythm guitar, etc) and control the volume of each seperately.

    I got all of that to work fine, but I cannot get a "seek bar" to work at all. I am pretty new to this and I'm not even sure it is possible.

    I am SURE I am missing something huge...just don't know what. I have spent hours looking through various forums...with no luck.

    I can get a slider to follow along with just one track (say..the drums) but can't make it skip forward or reverse, let alone do that with all audio files.

    Here is my code so far..the progSlider code is near the very bottom..can anyone help me....pretty please   ; )    (coding VB)

    Here is the code behind:


    Partial Public Class MainPage
        Inherits UserControl

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub play_button_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
       
            drums_only_mp3.Play()
            rhythm_guitar_only_mp3.Play()
            bass_guitar_only_mp3.Play()
            lead_guitar_only_mp3.Play()
        End Sub

        Private Sub pause_button_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
            drums_only_mp3.Pause()
            rhythm_guitar_only_mp3.Pause()
            bass_guitar_only_mp3.Pause()
            lead_guitar_only_mp3.Pause()
        End Sub

        Private Sub stop_button_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
       
            drums_only_mp3.Stop()
            rhythm_guitar_only_mp3.Stop()
            bass_guitar_only_mp3.Stop()
            lead_guitar_only_mp3.Stop()
       
        End Sub




    End Class

    AND HERE IS THE XAML:

    <UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:mixer_test_1"
    x:Class="mixer_test_1.MainPage"
    Width="640" Height="480" mc:Ignorable="d">

    <Grid x:Name="LayoutRoot" Background="White">
    <Rectangle Stroke="Black">
    <Rectangle.Fill>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="Black"/>
    <GradientStop Color="#FFAFC4F2" Offset="0.09"/>
    </LinearGradientBrush>
    </Rectangle.Fill>
    </Rectangle>
    <Slider x:Name="bass_slider" Height="160" HorizontalAlignment="Left" Margin="144,80,0,0" VerticalAlignment="Top" Width="16" Orientation="Vertical" Cursor="Hand" Maximum="1" Background="#FF9AA2F2" Value="0.5"/>
    <Slider x:Name="guitar_1_slider" Height="160" HorizontalAlignment="Left" Margin="224,80,0,0" VerticalAlignment="Top" Width="16" Orientation="Vertical" Cursor="Hand" Maximum="1" Background="#FFE8E197" Value="0.5"/>
    <Slider x:Name="guitar_2_slider" Height="160" HorizontalAlignment="Left" Margin="304,80,0,0" VerticalAlignment="Top" Width="16" Orientation="Vertical" Cursor="Hand" Maximum="1" Background="#FF92EC86" Value="0.5"/>
    <Slider x:Name="guitar_3_slider" Height="160" HorizontalAlignment="Right" Margin="0,80,240,0" VerticalAlignment="Top" Width="16" Orientation="Vertical" Cursor="Hand" Maximum="1" Background="#FFE29BE1"/>
    <Slider x:Name="guitar_4_slider" Height="160" HorizontalAlignment="Right" Margin="0,80,160,0" VerticalAlignment="Top" Width="16" Orientation="Vertical" Cursor="Hand" Maximum="1" Background="#FFB9A6EC"/>
    <Slider x:Name="vocal_slider" Height="160" Margin="0,80,80,0" VerticalAlignment="Top" Orientation="Vertical" Cursor="Hand" HorizontalAlignment="Right" Width="16" Maximum="1" Background="#FFA3A3A3"/>
    <TextBlock x:Name="Drums" Height="24" HorizontalAlignment="Left" Margin="57,0,0,206" VerticalAlignment="Bottom" Width="40" TextWrapping="Wrap"><Run Foreground="#FFF21313" Text="Drums"/></TextBlock>
    <TextBlock x:Name="Bass_Guitar" Height="34" HorizontalAlignment="Left" Margin="134,0,0,196" VerticalAlignment="Bottom" Width="38" TextAlignment="Center" TextWrapping="Wrap"><Run Foreground="#FFF21C1C" Text="Bass"/><LineBreak/><Run Foreground="#FFF41717" Text="Guitar"/></TextBlock>
    <TextBlock Height="34" HorizontalAlignment="Left" Margin="206,0,0,196" VerticalAlignment="Bottom" Width="60" TextAlignment="Center" TextWrapping="Wrap"><Run Foreground="#FFEC1A1A" Text="Guitar "/><Run Foreground="#FFF42020" Text="#"/><Run Foreground="#FFF21616" Text="1"/></TextBlock>
    <TextBlock Height="34" Margin="284,0,297,196" VerticalAlignment="Bottom" Foreground="#FFF60C0C" Text="Guitar #2" TextAlignment="Center" TextWrapping="Wrap"/>
    <TextBlock Height="34" HorizontalAlignment="Right" Margin="0,0,217,196" VerticalAlignment="Bottom" Width="57" Foreground="#FFFC0F0F" Text="Guitar #3" TextAlignment="Center" TextWrapping="Wrap"/>
    <TextBlock Height="24" HorizontalAlignment="Right" Margin="0,0,139,206" VerticalAlignment="Bottom" Width="61" Foreground="#FFEC1010" Text="Guitar #4" TextAlignment="Center" TextWrapping="Wrap"/>
    <TextBlock Height="14" HorizontalAlignment="Right" Margin="0,0,61,216" VerticalAlignment="Bottom" Width="58" Foreground="#FFF40D0D" Text="Vocals" TextAlignment="Center" TextWrapping="Wrap"/>
    <Button x:Name="play_button" Cursor="Hand" Height="24" HorizontalAlignment="Left" Margin="240,0,0,136" VerticalAlignment="Bottom" Width="80" RenderTransformOrigin="1.6,0.667" Foreground="#FF03185F" Content="Play" Click="play_button_Click">
    <Button.BorderBrush>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="#FFA3AEB9" Offset="0"/>
    <GradientStop Color="#FF8399A9" Offset="0.375"/>
    <GradientStop Color="#FF718597" Offset="0.375"/>
    <GradientStop Color="#FFF4120A" Offset="1"/>
    </LinearGradientBrush>
    </Button.BorderBrush>
    <Button.Background>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="Black" Offset="0"/>
    <GradientStop Color="#FFCB0101" Offset="1"/>
    </LinearGradientBrush>
    </Button.Background>
    </Button>
    <Button x:Name="pause_button" Height="24" HorizontalAlignment="Right" Margin="0,0,240,136" VerticalAlignment="Bottom" Width="80" Background="#FFE01504" Foreground="#FF050963" Content="Pause" Click="pause_button_Click">
    <Button.BorderBrush>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="#FFA3AEB9" Offset="0"/>
    <GradientStop Color="#FF8399A9" Offset="0.375"/>
    <GradientStop Color="#FF718597" Offset="0.375"/>
    <GradientStop Color="#FFE01504" Offset="1"/>
    </LinearGradientBrush>
    </Button.BorderBrush>
    </Button>
    <Button x:Name="stop_button" Height="24" HorizontalAlignment="Right" Margin="0,0,156,136" VerticalAlignment="Bottom" Width="80" Background="#FFE01504" Foreground="#FF050963" Content="Stop" Click="stop_button_Click">
    <Button.BorderBrush>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="#FFA3AEB9" Offset="0"/>
    <GradientStop Color="#FF8399A9" Offset="0.375"/>
    <GradientStop Color="#FF718597" Offset="0.375"/>
    <GradientStop Color="#FFE01504" Offset="1"/>
    </LinearGradientBrush>
    </Button.BorderBrush>
    </Button>
    <TextBlock Height="24" HorizontalAlignment="Right" Margin="0,0,72,136" VerticalAlignment="Bottom" Width="80" Text="Tempo (BPM)" TextWrapping="Wrap"/>
    <TextBlock x:Name="song_info_panel" Height="144" HorizontalAlignment="Left" Margin="8,0,0,16" VerticalAlignment="Bottom" Width="216" Opacity="0.8" Foreground="#FFF00808" TextWrapping="Wrap"><TextBlock.OpacityMask>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="#FF0C0ABF" Offset="0"/>
    <GradientStop Color="#FF8D8CEE" Offset="1"/>
    </LinearGradientBrush>
    </TextBlock.OpacityMask><Run Text="JamAlone Song Info Panel"/><LineBreak/><Run Text=""/><LineBreak/><Run Text="Artist: Greenday"/><LineBreak/><Run Text="Song: When I Come Around"/><LineBreak/><Run Text="Tempo: 120"/><LineBreak/><Run Text="ASCAP#:"/></TextBlock>
    <TextBlock Height="81" Margin="240,0,40,16" VerticalAlignment="Bottom" TextWrapping="Wrap"><Run Text="Track Assignment:"/><LineBreak/><Run Text="Guitar # 1 = Rhythm Guitar"/><LineBreak/><Run Text="Guitar # 2 = Lead Guitar"/><LineBreak/><Run Text="Guitar # 3 = blank (N/A)"/><LineBreak/><Run Text="Guitar # 4 = blank (N/A)"/></TextBlock>
    <TextBlock Height="40" HorizontalAlignment="Left" Margin="8,8,0,0" VerticalAlignment="Top" Width="176" Text="JAMLAB " TextWrapping="Wrap"/>
    <CheckBox x:Name="drum_mute" Height="16" HorizontalAlignment="Left" Margin="49,64,0,0" VerticalAlignment="Top" Width="48" Content="Mute"/>
    <CheckBox x:Name="drum_solo" Height="16" HorizontalAlignment="Left" Margin="49,48,0,0" VerticalAlignment="Top" Width="64" Content="Solo"/>
    <MediaElement x:Name="drums_only_mp3" Height="0" HorizontalAlignment="Right" Margin="0,200,274,0" VerticalAlignment="Top" Width="0" Source="/drums_only.mp3" Stretch="Fill" Volume="{Binding Value, ElementName=drum_slider, Mode=OneWay}" AutoPlay="False"/>
    <MediaElement x:Name="rhythm_guitar_only_mp3" Height="0" HorizontalAlignment="Right" Margin="0,80,217,0" VerticalAlignment="Top" Width="0" Source="/rhythm_guitar_only.mp3" Stretch="Fill" Volume="{Binding Value, ElementName=guitar_1_slider, Mode=OneWay}" AutoPlay="False"/>
    <CheckBox x:Name="bass_solo" Height="16" HorizontalAlignment="Left" Margin="128,48,0,0" VerticalAlignment="Top" Width="52" Content="Solo"/>
    <CheckBox x:Name="guitar_1_solo" Height="16" HorizontalAlignment="Left" Margin="202,48,0,0" VerticalAlignment="Top" Width="64" Content="Solo"/>
    <CheckBox x:Name="guitar_2_solo" Height="16" Margin="284,48,292,0" VerticalAlignment="Top" Content="Solo"/>
    <CheckBox x:Name="guitar_3_solo" Height="16" HorizontalAlignment="Right" Margin="0,48,217,0" VerticalAlignment="Top" Width="64" Content="Solo"/>
    <CheckBox x:Name="guitar_4_solo" Height="16" HorizontalAlignment="Right" Margin="0,48,136,0" VerticalAlignment="Top" Width="64" Content="Solo"/>
    <CheckBox x:Name="vocal_solo" Height="16" HorizontalAlignment="Right" Margin="0,48,55,0" VerticalAlignment="Top" Width="64" Content="Solo"/>
    <CheckBox x:Name="bass_mute" Height="16" HorizontalAlignment="Left" Margin="128,64,0,0" VerticalAlignment="Top" Width="48" Content="Mute"/>
    <CheckBox x:Name="guitar_1_mute" Height="16" HorizontalAlignment="Left" Margin="202,64,0,0" VerticalAlignment="Top" Width="48" Content="Mute"/>
    <CheckBox x:Name="guitar_2_mute" Height="16" Margin="284,64,308,0" VerticalAlignment="Top" Content="Mute"/>
    <CheckBox x:Name="guitar_3_mute" Height="16" HorizontalAlignment="Right" Margin="0,64,233,0" VerticalAlignment="Top" Width="48" Content="Mute"/>
    <CheckBox x:Name="guitar_4_mute" Height="16" HorizontalAlignment="Right" Margin="0,64,152,0" VerticalAlignment="Top" Width="48" Content="Mute"/>
    <CheckBox x:Name="vocal_mute" Height="16" Margin="0,64,71,0" VerticalAlignment="Top" Content="Mute" HorizontalAlignment="Right" Width="48"/>
    <Slider x:Name="drum_slider" Height="160" HorizontalAlignment="Left" Margin="64,80,0,0" VerticalAlignment="Top" Width="16" Orientation="Vertical" Cursor="Hand" Maximum="1" BorderThickness="1" Background="#FFE29696" Padding="0" Value="0.5">
    <Slider.BorderBrush>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="#FFA3AEB9" Offset="0"/>
    <GradientStop Color="#FF8399A9" Offset="0.375"/>
    <GradientStop Color="#FF718597" Offset="0.375"/>
    <GradientStop Color="#FF020C14" Offset="1"/>
    </LinearGradientBrush>
    </Slider.BorderBrush>
    </Slider>
    <MediaElement x:Name="bass_guitar_only_mp3" Height="0" HorizontalAlignment="Left" Margin="172,16,0,0" VerticalAlignment="Top" Width="0" Source="/bass_guitar_only.mp3" Stretch="Fill" Volume="{Binding Value, ElementName=bass_slider, Mode=OneWay}" AutoPlay="False"/>
    <MediaElement x:Name="lead_guitar_only_mp3" Height="0" HorizontalAlignment="Left" Margin="250,24,0,0" VerticalAlignment="Top" Width="0" Source="/lead_guitar_only.mp3" Stretch="Fill" AutoPlay="False"/>
    <Slider x:Name="bpm_slider" Height="12" Margin="240,0,156,184" VerticalAlignment="Bottom" Maximum="5" Cursor="Hand" Value="{Binding Balance, ElementName=drums_only_mp3, Mode=OneWay}" Minimum="-5"/>
    <Slider x:Name="progSlider" Height="31" Margin="240,0,72,101" VerticalAlignment="Bottom" Value="{Binding Position.TotalSeconds, ElementName=rhythm_guitar_only_mp3, Mode=TwoWay}" Maximum="328" Cursor="Hand" DataContext="{Binding Triggers[0].Dispatcher, ElementName=play_button, Mode=OneWay}"/>
    </Grid>
    </UserControl>



    Wednesday, December 9, 2009 11:01 PM