Trying to create an mp3 embedder for personal use. Tried all of the solutions here on StackO, but none have worked.
Here is what I have:
TagLib.File tagFile = TagLib.File.Create("C:\\Users\\Dom\\Desktop\\song.mp3");
TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame();
pic.TextEncoding = TagLib.StringType.Latin1;
pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg;
pic.Type = TagLib.PictureType.FrontCover;
pic.Data = TagLib.ByteVector.FromPath("C:\\Users\\Dom\\Pictures\\picture.png");
tagFile.Tag.Pictures = new TagLib.IPicture[1] { pic };
tagFile.Tag.Album = "Album 1";
tagFile.Tag.Year = 1990;
tagFile.Save();
The album tag and year tag show up fine under properties, and the program is not crashing or throwing any errors. Picture does not show up as the file icon, or in windows media player. Picture size is 300x300 pixels if that has any importance.
The reason is probably some conflict with existing ID3v2 Tags. Fix it like this:
TagLib.File tagFile = TagLib.File.Create("C:\\Users\\Dom\\Desktop\\song.mp3");
Tag t = tagFile.GetTag(TagTypes.Id3v2);
tagFile.RemoveTags(TagTypes.Id3v2);
Tag tags = tagFile.GetTag(TagTypes.Id3v2);
tagFile.GetTag(TagTypes.Id3v2, true);
tagFile.Save();
tagFile = TagLib.File.Create("C:\\Users\\Dom\\Desktop\\song.mp3");
tags = t;
tagFile.GetTag(TagTypes.Id3v2).Pictures = new IPicture[] {
new Picture("C:\\Users\\Dom\\Pictures\\picture.png")
{ MimeType = "image/png", Type = PictureType.FrontCover }
};
tagFile.Tag.Album = "Album 1";
tagFile.GetTag(TagTypes.Id3v2).Track = 0;
tagFile.Tag.Year = 1990;
tagFile.Save();
Related
I'm sure it's something stupid I'm doing but I can't figure it out. I'm trying to write a KML from scratch. It will be inside a KMZ with a bunch of georeferenced pictures that I won't to show up as photo overlays. I can't get it to write a KML though, I find the documentation too basic to incorporate a Folder. When I pause the program and debug, it shows Kml kml as having no children, but the feature 'folder' has 42. And then the namespaces aren't showing up, and it's not writing the Kml file. Please, any help you can give me!
public void WriteKML_sharp()
{
Kml kml = new Kml();
kml.AddNamespacePrefix(KmlNamespaces.GX22Prefix, KmlNamespaces.GX22Namespace);
Folder folder = new Folder();
kml.Feature = folder;
foreach (Picture picture in _process.pictures)
{
PhotoOverlay photooverlay = new PhotoOverlay();
photooverlay.Name = picture.name + picture.extension;
photooverlay.Open = true;
photooverlay.Shape = Shape.Rectangle;
Icon icon = new Icon();
Uri uri = new Uri(Path.Combine("files", picture.name + picture.extension), UriKind.Relative);
icon.Href = uri;
photooverlay.Icon = icon;
Point point = new Point();
point.Coordinate = new Vector(picture.gpslat, picture.gpslong);
//point.Coordinate = new Vector(picture.gpslat, picture.gpslong, picture.gpsalt);
point.AltitudeMode = AltitudeMode.RelativeToGround;
photooverlay.Location = point;
ViewVolume viewvolume = new ViewVolume();
viewvolume.Top = 25;
viewvolume.Bottom = -25;
viewvolume.Left = 20;
viewvolume.Right = -20;
photooverlay.View = viewvolume;
folder.AddFeature(photooverlay);
}
KmlFile kmlfile = KmlFile.Create(kml, false);
using (var stream = System.IO.File.OpenWrite(_filename))
{
kmlfile.Save(stream);
}
}
I am not sure if this will be the reason but u can try adding a document in the KML file and assign that document as kml.Feature and Add your feature to this document using .AddFeature(folder);
It works for me that way
i want to play the video which name is entered in text box. But it does not play the exact video it plays the first video present in folder. any help please..
Code
String vid_name = data.Text;
string complete_name = vid_name.ToLower() + ".mp4";
string root = System.IO.Path.GetDirectoryName("D:/abc");
string[] supportedExtensions = new[] { ".mp4" };
var files = Directory.GetFiles(Path.Combine(root, "Videos"), "*.*").Where(s => supportedExtensions.Contains(Path.GetExtension(s).ToLower()));
List<VideosDetail> videos = new List<VideosDetail>();
VideosDetail id;
foreach (var file in files)
{
id = new VideosDetail()
{
Path = file,
FileName = Path.GetFileName(file),
Extension = Path.GetExtension(file)
};
FileInfo fi = new FileInfo(file);
id.FileName = fi.Name;
id.Size = fi.Length;
videos.Add(id);
if (id.FileName == complete_name)
{
VideoList.ItemsSource = videos; //**Problem comes here
}
else
{
MessageBox.Show("no such video is available. ");
}
}
Since videos is a List, the line
VideoList.ItemsSource = videos;
Points to all the videos in the folder (up to the one that actually matches the filename you entered). Hence, the unwanted result.
You should probably pass the index of the video in your list, something like:
player.Source = videos[x];
Hope this helps!
I am new to C# and currently I am trying to make an audio player using BASS library. Right now I am creating the playlist using INI files like below:
[songs]
1=c:\lamfao.mp3
2=c:\test.mp3
[total_songs]
total=2
Everything is fine, but loading this type of INI file and showing it in ListView consumes a lot of time. Also there's no way to delete a song from this INI files. Hence, I am looking for help regarding loading and creating the playlists in C#. What I wanted to do is create a playlist with songs path and if possible with ID3 information like Album, Artist and Genre.
Also like other media players, for example WinAMP or MediaMonkey, they take no time to display the playlist, how this can be achieved. I am trying to show the playlist in ListView with Type=Details.
Is it possible to avoid the insertion of duplicate song in playlist?
Here's the current code which I am using to read INI files.
ListViewItem lvi;
ListViewItem.ListViewSubItem lvsi;
string name = "";
string album = "";
string artist = "";
string path = "";
if (File.Exists(CurrentPlaylistLocation))
{
this.progressBar1.Visible = true;
IniFile ini = new IniFile(CurrentPlaylistLocation); // INI Reading class in C# using Win32 API wrapper
string Total = ini.IniReadValue("Total_Files", "Total");
int items = Convert.ToInt32(Total);
this.progressBar1.Minimum = 0;
this.progressBar1.Maximum = items;
this.progressBar1.MarqueeAnimationSpeed = 100;
this.progressBar1.Style = ProgressBarStyle.Blocks;
int total = 0;
listView1.BeginUpdate();
for (int i = 1; i <= items; i++)
{
path = ini.IniReadValue("songs", Convert.ToString(i));
if(File.Exists(path))
{
// When user deletes a song from playlist, I add a .ignore in the last of song path
// so, check if a song is deleted by user, if deleted then do not add it
if (System.IO.Path.GetExtension(path).ToLower() != ".ignore")
{
PlayerEngine.GetTrackData(path, out name, out artist, out album); // Get META tag using Taglib sharp
lvi = new ListViewItem();
lvi.Text = name;
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = album;
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = artist;
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = path;
lvi.SubItems.Add(lvsi);
this.listView1.BeginUpdate();
this.listView1.Items.Add(lvi);
this.listView1.EndUpdate();
total++;
this.progressBar1.Value = (i);
}
}
}
listView1.EndUpdate();
PlayerEngine.TotalTrackInTempPlaylist = listView1.Items.Count-1; // update the total number of songs loaded in player engine class
this.progressBar1.Visible = false;
MessageBox.Show("Playlist loading completed!");
Thanking you
I am having an error when converting/reading 2 pages .tif files . What is the right approach for this?
Here's the error:
ImageMagick.MagickCoderErrorException: Magick: C:\DigitalAssets\sample.TIF: Null count for "Tag 33426" (type 4, writecount -3, passcount 1). `_TIFFVSetField' # error/tiff.c/TIFFErrors/561
at ImageMagick.MagickImage.HandleReadException(MagickException exception)
at ImageMagick.MagickImage.Read(String fileName, MagickReadSettings readSettings)
at Digital_Asset_Converter_Service.Service.EPSFolderWatcher_Created(Object sender, FileSystemEventArgs e)
Here's the code:
string fileName = #"C:\DigitalAssets\sample.tif";
using (MagickImageCollection image = new MagickImageCollection())
{
MagickReadSettings settings = new MagickReadSettings();
// settings.ColorSpace = ColorSpace.RGB;
settings.Density = new MagickGeometry(300, 300);
//settings.FrameIndex = 0;
// settings.FrameCount = 1;
image.Read(fileName,settings);
}
Your image contains a corrupt tiff tag that causes a MagickCoderErrorException. We made a change to ImageMagick that will allow you to ignore a specific tiff tag. Below is an example that will prevent the MagickCoderErrorException:
using (MagickImage image = new MagickImage())
{
image.SetDefine(MagickFormat.Tiff, "ignore-tags", "33426");
// Or if you want to ignore multiple tags:
image.SetDefine(MagickFormat.Tiff, "ignore-tags", "33426,33428");
MagickReadSettings settings = new MagickReadSettings();
// settings.ColorSpace = ColorSpace.RGB;
settings.Density = new MagickGeometry(300, 300);
image.Read(fileName, settings);
}
I'm converting mp3 to wma with expression encoder sdk 4 with the code below
A wma file is produced but it is missing the thumbnail / image / cover from the mp3 file.
using (var job = new Job())
{
var mediaItem = new MediaItem(input.FullName)
{
OutputFileName = outputFileName,
OutputFormat =
{
AudioProfile =
{
Codec = AudioCodec.Wma,
Bitrate = BitRate ?? BitRate,
Channels = 1
}
}
};
job.MediaItems.Add(mediaItem);
job.OutputDirectory = OutputDirectory;
job.CreateSubfolder = false;
job.Encode();
}
I have tried the following:
1)
mediaItem.MarkerThumbnailCodec = ImageFormat.Jpeg;
mediaItem.MarkerThumbnailJpegCompression = 0;
mediaItem.MarkerThumbnailSize = new Size(50, 50);
2)
mediaItem.ThumbnailCodec = ImageFormat.Jpeg;
mediaItem.ThumbnailEmbed = true;
mediaItem.ThumbnailJpegCompression = 50;
mediaItem.ThumbnailMode = ThumbnailMode.BestFrame;
mediaItem.ThumbnailSize = new Size(50, 50);
mediaItem.ThumbnailTime = TimeSpan.FromSeconds(0);
3)
mediaItem.OverlayFileName = #"c:\Chrysanthemum.jpg";
mediaItem.OverlayStartTime = TimeSpan.FromSeconds(0);
..but it doesn't help.
Please help me :)