|
I wondered if there is a possibility to listen to two or more MP3's at the same time and thus mixing them to the audio output, and also handle their volume apart. I saw an application such as Virtual DJ, and I would like to write a C# Winforms application but with very basic possibilities, mixing 2-3 mp3 files, handle their volume separately, and if possible listen to the headphones separately (pre-listening) while another audio file is playing. I looked for code here and there, but the only thing I found was mixing mp3 files and save them to a new file without listening....
|
|
|
|
|
You can have multiple "media elements" playing at the same time; each with their own music source and settings. Beyond that, it's up to you, your equipment, and the app.
"Pre-listening" implies "saving" / buffering. Why is "creating a new file" an issue? It's temporary; and I doubt "pre-listening" means the whole thing (which overlaps with other activities ... and that's why you probably need multiple machines too).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Thank you Gerry. Creating a new file, temporary, is not directly an issue, it is not a goal on itself. What I want to do is, when one audio file is playing using the output, I would like to pre-listen to another one for instance in the headphones, just like DJ's do.
I wonder if I should give NAudio a try.
|
|
|
|
|
I use this code in a button to save data into a SQLite file:
string conString = @"URI=file:" + Application.StartupPath + "\\DataBase.db";
SQLiteConnection con = new SQLiteConnection(conString);
SQLiteCommand cmd = new SQLiteCommand(con);
con.Open();
try
{
cmd.CommandText = "INSERT INTO FileInfo(EqpCode, EqpName, FileName) VALUES(@EqpCode, @EqpName, @FileName)";
for (int i = 0; i < myTable02.Rows.Count; i++)
{
string EqpCode = myTable02.Rows[i][0].ToString();
string EqpName = myTable02.Rows[i][1].ToString();
string FileName = myTable02.Rows[i][2].ToString();
cmd.Parameters.AddWithValue(@EqpCode, EqpCode);
cmd.Parameters.AddWithValue(@EqpName, EqpName);
cmd.Parameters.AddWithValue(@FileName, FileName);
cmd.ExecuteNonQuery();
}
con.Close();
}
catch (Exception)
{
throw;
}
The error is thrown in cmd.ExecuteNonQuery() line:
System.Data.SQLite.SQLiteException: 'unknown error
Insufficient parameters supplied to the command'
Please help me.
|
|
|
|
|
cmd.Parameters.AddWithValue(@EqpCode, EqpCode);
cmd.Parameters.AddWithValue(@EqpName, EqpName);
cmd.Parameters.AddWithValue(@FileName, FileName);
You need to enclose the parameter names in quotes. They are the strings that identify which parameter they go to in the SQL statement.
cmd.Parameters.AddWithValue("@EqpCode", EqpCode);
cmd.Parameters.AddWithValue("@EqpName", EqpName);
cmd.Parameters.AddWithValue("@FileName", FileName);
|
|
|
|
|
Look at your code.
Instead of inserting a new row each time, you are adding subsequent rows to the existing parameters set by the previous iteration.
So the first row passes 3 pieces of data, the second passes 6, the third 9, and so on ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
I use this:
string[]my_array = Directory.GetFiles(@"Resources\PDFs", "*.pdf");
But, it represents the full path and file name. I want to have only the file names. How can I achieve it?
|
|
|
|
|
Try:
string[] filesWithPath = Directory.GetFiles(@"Resources\PDFs", "*.pdf");
string[] filesWithoutPath = filesWithPath.Select(f => Path.GetFileName(f)).ToArray();
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Solved. Thanks.
modified 5-Jul-21 11:01am.
|
|
|
|
|
I was just going to say:
"It doesn't work" is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.
But you should know that by now ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thank you. It worked. It was my fault. Excuse me.
|
|
|
|
|
No problem!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I want to update an existing XML file in DropBox without uploading and replacing a new file. Is it possible using DropBox API?
|
|
|
|
|
After a quick look at the documentation for the API, found here[^], no, you can't.
|
|
|
|
|
Hi
I want to add Label and Farme controls in a way that Label's text is placed inside the Frame and the Frame size is changed based on text lenght. Actually, I want to add this XAML code by clicking a button:
<StackLayout x:Name="MyStack">
<Frame BackgroundColor="GreenYellow" CornerRadius="5" Padding="5">
<Label Text="Just For Test" FontAttributes="Bold" FontSize="Medium" />
</Frame>
</StackLayout>
between these code:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MReport.TabbedMainPage">
<ContentPage Title="New Report" IconImageSource="NewReport.png" BackgroundImageSource="blue_windows.jpg">
<StackLayout Margin="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollView>
<StackLayout x:Name="MyStack">
</StackLayout>
</ScrollView>
<Button Grid.Row="1" Text="Add New Item" Clicked="Button_Clicked" />
</Grid>
<Button Grid.Row="1" Text="Send" />
</StackLayout>
</ContentPage>
<ContentPage Title="Report History" IconImageSource="History.png" BackgroundImageSource="blue_windows.jpg" />
<ContentPage Title="Messages" IconImageSource="Message.png" BackgroundImageSource="blue_windows.jpg"/>
</TabbedPage>
I tried this:
private async void Button_Clicked(object sender, EventArgs e)
{
MyStack.Children.Add(new Frame { CornerRadius = 5, BackgroundColor = Color.Azure});
MyStack.Children.Add(new Label { Text = time_text[0].ToString() });
MyStack.Children.Add(new Label { Text = time_text[1].ToString(), FontAttributes = FontAttributes.Bold, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)) });
}
But it cannot add text inside the Frame.
Please help me.
modified 1-Jul-21 12:51pm.
|
|
|
|
|
You create the Frame; you add the labels to the Frame; THEN you add the Frame to the StackLayout. (Or maintain a Frame reference.)
You're just adding everything to the StackLayout.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Ok, Solved. Thanks. 
modified 1-Jul-21 13:53pm.
|
|
|
|
|
hi, i have a datagridview where i get the Ids and the amount in the first and second column,
but the third column should show me a function code for example compared to the
dataGridView2.Rows [dvd] .Cells [0] .Value
but, it displays them to me at the bottom instead of that evening on the same line
but, it displays them to me at the bottom instead of that evening on the same line
here is the code
void gab2relik()
{
cnx = new SqlConnection(db.RXcon);
try
{
cnx.Open();
}
catch
{
MessageBox.Show("Erreure lors de la Connexion");
}
if (dataGridView2.Rows.Count>0)
{
for (int dvd = 0; dvd < dataGridView2.Rows.Count; dvd++)
{
string ct = "select grade from fction inner join person on person.id= fction.id where id ='" + dataGridView2.Rows[dvd].Cells[0].Value + "'";
commd222 = new SqlCommand(ct);
commd222.Connection = cnx;
try
{
SqlDataReader d = commd222.ExecuteReader();
d.Read();
DataGridViewRow Row = (DataGridViewRow)dataGridView2.Rows[0].Clone();
Row.Cells[2].Value = d["grade"].ToString();
d.Close();
dataGridView2.Rows.Add(Row);
}
catch (Exception tt)
{
MessageBox.Show(tt.Message.ToString());
}
finally
{
}
}
}
modified 1-Jul-21 6:33am.
|
|
|
|
|
remiki wrote:
string ct = "select grade from fction inner join person on person.id= fction.id where id ='" + dataGridView2.Rows[dvd].Cells[0].Value + "'"; Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
Beyond that, you need to update your code to store the value in the expected row, rather than adding a new row at the bottom.
You should also stop storing connections in class-level fields. Instead, create them when they're required, and wrap them in using blocks to ensure they are always disposed of properly.
void gab2relik()
{
if (dataGridView2.Rows.Count == 0) return;
using (var conn = new SqlConnection(db.RXcon))
using (var cmd = new SqlCommand("SELECT grade FROM fction INNER JOIN person ON person.id = fction.id WHERE fction.id = @ID", conn))
{
var pID = cmd.Parameters.Add("@ID", SqlDbType.VarChar);
try
{
conn.Open();
}
catch
{
MessageBox.Show("Erreure lors de la Connexion");
return;
}
foreach (DataGridViewRow row in dataGridView2.Rows)
{
pID.Value = row.Cells[0].Value ?? DBNull.Value;
row.Cells[2].Value = cmd.ExecuteScalar();
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
That's some odd code ... but ...
Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable; Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT
DROP TABLE MyTable; A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
When you've fixed that through your whole app, start looking at that code.
Why are you reading each grade separately? Just issue one SQL command and read the lot - use a DataAdapter and read it all into a DataTable - then use that data to fill each row.
What you are doing is causing a heck of a lot of work for both your system and the DB Server, and you aren't even checking to see if any matching row exists!
You aren't disposing - or even closing - the connection: put that in a using block and teh system will "tidy up" behind you.
Your finally block is irrelevant, since you don't do anything in it!
And ... why are you adding rows to the DGV that you are using to limit how many times you go round the loop? That will never end until something somewhere fails - and then you will get message box after message box because it's in a try...catch inside the loop!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
I want to write a code like this that runs perfectly in WinForms:
int count = 0;
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(Label))
if (((Label)c).BackColor == Color.Red)
count++;
}
But in Xamarin, I cannot use Control class. There is no namespace for it. How can I do the same in Xamarin?
|
|
|
|
|
Your WinForms code would be better written as:
int count = 0;
foreach (Label l in this.Controls.OfType<Label>())
{
if (l.BackColor == Color.Red)
{
count++;
}
} Or simply:
int count = this.Controls.OfType<Label>().Count(l => l.BackColor == Color.Red);
Xamarin forms doesn't have a similar concept. You might be able to do something similar by walking the visual tree - eg:
the urban canuk, eh: VisualTreeHelper for Xamarin.Forms[^]
However, it would almost certainly be better to use MVVM concepts to achieve your goal.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I'm working on Xamarin project. I want to pass a parameter from one page to another.
I used this code for one of pages:
public TabbedMainPage(string parameter)
{
InitializeComponent();
On<Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
On<Android>().SetIsSmoothScrollEnabled(false);
lbl01.Text = parameter;
}
App.xaml.cs:
public App()
{
InitializeComponent();
MainPage = new TabbedMainPage();
}
I have error under
TabbedMainPage in App.xaml.cs
How can I solve that error?
|
|
|
|
|
MainPage = new TabbedMainPage( <parameter> );
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|