I've been searching for a couple of days on how to get the album art for a song (or a frame capture of a video) from a file path. All I could find is things related to Mediastore like this answer where it requires getting the album ID of the file.
Cursor cursor = getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
new String[] {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART},
MediaStore.Audio.Albums._ID+ "=?",
new String[] {String.valueOf(albumId)},
null);
if (cursor.moveToFirst()) {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
// do whatever you need to do
}
But I can't find a guid on how it works, how can pass the file to Mediastore or how can I get the album ID of the media or anything... Currently I get the media information using MediaMetadataRetriever but I can't find a way to get the album art or a video thumbnail of a media file using it...
** Update :-
If Mediastore must be used to get the media files in the first place before using it to get their data, I can implement it instead of what I'm currently doing (Currently I iterate the device files to get the supported files) and it can be a better option as Mediastore supports getting data from external storages as well.
Any help is appreciated.
If using MediaMetadataRetriever , you can have a try with follow sample code :
private void loadingCover(string mediaUri)
{
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.SetDataSource(mediaUri);
byte[] picture = mediaMetadataRetriever.GetEmbeddedPicture();
Android.Graphics.Bitmap bitmap = BitmapFactory.DecodeByteArray(picture, 0, picture.Length);
musicCover.SetImageBitmap(bitmap);
}
In addition , not forgatting to add permission :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Invoke it as follow :
File file = new File("/storage/sdcard/Movies/music1.mp4");
if (file.Exists())
{
loadingCover(file.AbsolutePath);
}
Related
I am using EDI.Net from indice-co and i have a EDI file that contains multiple items, when i use the EdiGrammer.NewEdiFact and read the file using stream and deserialize it I get only 1 item from the file, the top most; how do i read the file using stream and deserialize it to a list?
Code Example:
var editFactParser = EdiGrammar.NewEdiFact();
var interchange = default(EdiModel.Interchange);
using (
var stream = File.Open("E:\\SomePath\\20191121020103.00000091.EDI", FileMode.Open,
FileAccess.Read))
{
interchange = new EdiSerializer().Deserialize<EdiModel.Interchange>(new StreamReader(stream),
editFactParser );
}
EdiFact File Content
UNA:+.? 'UNB+UNOA:2+DHLEUAPGW+CENTIRO+191030:1347+203516'UNH+240179+IFTSTA:D:01B:UN'BGM+77+9690108+9'DTM+9:201910301347:203'NAD+CZ+9690108'CNI+1+1032173'LOC+5+AMS::87'LOC+8+AMS::87'STS++PU+:::SHIPMENT PICKUP'RFF+CN:1297617'DTM+11:20191030:102'DTM+7:201910301329:203'GID++1'PCI+18'GIN+BN+10321732'UNT+15+240179'UNH+240180+IFTSTA:D:01B:UN'BGM+77+9690108+9'DTM+9:201910301347:203'NAD+CZ+96901083'CNI+1+2598018'LOC+5+ORY::87'LOC+8+AMS::87'STS++PL+:::PROCESSED AT LOCATION'RFF+CN:116775116'DTM+11:20191029:102'DTM+7:201910301336:203'GID++1'PCI+18'GIN+BN+2598018043'CNI+2+4911357323'LOC+5+CDG::87'LOC+8+AMS::87'STS++PL+:::PROCESSED AT LOCATION'RFF+CN:1286700'DTM+11:20191029:102'DTM+7:201910301339:203'GID++1'PCI+18'GIN+BN+49113573'CNI+3+4911401'LOC+5+CDG::87'LOC+8+AMS::87'STS++PL+:::PROCESSED AT LOCATION'RFF+CN:129007'DTM+11:20191029:102'DTM+7:201910301337:203'GID++1'PCI+18'GIN+BN+49114019'CNI+4+6194460'LOC+5+BRU::87'LOC+8+AMS::87'STS++PL+:::PROCESSED AT LOCATION'RFF+CN:127214241'DTM+11:20191029:102'DTM+7:201910301339:203'GID++1'PCI+18'GIN+BN+6194460856'CNI+5+7525715'LOC+5+ORY::87'LOC+8+AMS::87'STS++PL+:::PROCESSED AT LOCATION'RFF+CN:ECONOCOM'DTM+11:20191029:102'DTM+7:201910301336:203'GID++1'PCI+18'GIN+BN+75257154'CNI+6+752571'LOC+5+ORY::87'LOC+8+AMS::87'STS++PL+:::PROCESSED AT LOCATION'RFF+CN:ECONOCOM'DTM+11:20191029:102'DTM+7:201910301339:203'GID++1'PCI+18'GIN+BN+7525715'UNT+65+240180'UNZ+2+203516'
sorry for the late reply, I was able to solve it, it was an issue how with how I was accessing the segments and what data I was trying to get back, after some more trial and error I was able to figure it out, I currently do not have access to the code and will try and post it back here when I get to it. Thank you.
I have a container and a blob of mp4 type in my Azure storage account.
I am able to stream it from the Blob.Uri (or using SAS token if required) in HTML5 video control.
But I need to convert that Blob Uri to be converted as "blob:" url so copying the source from developer's tool will not play the video in any new window.
I don't want to download the full video first anywhere.
Thanks in advance!
I am showing/streaming the video like:
List<string> blobPaths = new List<string>();
foreach (IListBlobItem item in container.ListBlobs(useFlatBlobListing: true))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blb = (CloudBlockBlob)item;
string sasToken = blb.GetSharedAccessSignature(null, "spolicy");
blobPaths.Add(string.Format(CultureInfo.InvariantCulture, "{0}{1}", blb.Uri, sasToken));
}
}
ViewBag.Path1 = blobPaths[0];
Main point is that I want Netflix type of feature, so that copying the video source from web page's view source won't work.
Also video should not be downloaded locally.
I am developing a flutter demo app. I want to use metadata about a video in my phone storage. I am able to extract the path of that video, but don't know how to extract its metadata in dart/flutter.
I need the following metadata:
Duration of video
Name of video
Size of video
When video was taken
You can use the VideoPlayerController.file constructor from the official video player plugin (which is maintained by the official google team so you don't have to worry about its future and stability) to access the file and get the following meta after you install the package:
first this is your VideoPlayerController:
VideoPlayerController controller = new VideoPlayerController.file('');//Your file here
Duration:
controller.value.duration ;
Video Name, this should already be possessed with you as you can reach the file path and pass it to the player constructor.
3.Video Size:
controller.value.size ;
4.As for when the video was taken I can't help you with this. You have to find another way to figure it out.
One of the ways to get the creation time of the video in FLutter is to use flutter_ffmpeg plugin.
Add it to the pubspec.yaml:
dependencies:
flutter_ffmpeg: ^0.3.0
Get the file path of your video, for example with file_picker:
File pickedFile = await FilePicker.getFile();
Get meta data of the video by its path using ffmpeg:
final FlutterFFprobe flutterFFprobe = FlutterFFprobe();
MediaInformation mediaInformation = await flutterFFprobe.getMediaInformation(pickedFile.path);
Map<dynamic, dynamic> mp = mediaInformation.getMediaProperties();
String creationTime = mp["tags"]["creation_time"];
print("creationTime: $creationTime");
And in the console you'll get smth like this:
I/flutter (13274): creationTime: 2020-09-24T17:59:24.000000Z
Along with creation time, there are other useful details:
Note: adding this plugin to your app increases the weight of your final apk!
your code is correct Mazin Ibrahim you just need to initialize it. the future value will return all the details.
Future getVideo() async {
await MultiMediaPicker.pickVideo(source: ImageSource.gallery).then((video){
File _video = video;
VideoPlayerController fileVideocontroller = new VideoPlayerController.file(_video)
..initialize().then((_) {
debugPrint("========"+fileVideocontroller.value.duration.toString());
});
});
}
When I am trying to upload multiple images using Umbraco Drag and Drop functioanlity, I am getting No property type exists with alias umbracoFile. I have custom media type Top Banner with alias name banner. When I upload the image, it is using the custom media type as contentTypeAlias. The custom media type doesn't have a property named umbracoFile. So, I need to change this behavior. I need to use default File/Image media type for uploading the image. How I can achieve it?
I have created a new Media Type 'Top Banner'(Alias:Banner) and properties on Banner media type
Title(TextString)
Banner Image(Image Cropper)
Image(FIleUpload)
Link(Content Picker)
Subtitle((TextString))
VideoLink (TextString)
Centered(checkbox)
Logo(FIleupload)
Is Black Layout for Link Text(checkbox)
If I am adding a property umbracoFile(Property Type : FileUpload) into Banner Media type, the files are getting uploaded and no error is coming.
Exception Details:
No property type exists with alias umbracoFile.
Stack Trace:
at Umbraco.Core.IO.MediaFileSystem.GetProperty(IContentBase content, String propertyTypeAlias)
at Umbraco.Core.IO.MediaFileSystem.SetUploadFile(IContentBase content, String propertyTypeAlias, String filename, Stream filestream)
at Umbraco.Core.Models.ContentExtensions.SetValue(IContentBase content, String propertyTypeAlias, String filename, Stream filestream)
at Umbraco.Web.Editors.MediaController.<PostAddFile>d__26.MoveNext()
These are the Media types
Ok, so. What's happening is that Umbraco tries to determine what the media type is in a couple of ways - first, on the Client side in JavaScript it checks to see what Media Types are allowed in the particular folder you're adding files to.
If you have a recent version of Umbraco (since around November last year), it should be giving you the option to choose which Media Type to upload the files to if you've got more than one allowed type for the folder you're uploading to, otherwise it will silently choose Image or File depending on the extension of the file you're uploading.
The error you're getting may indicate that you're choosing the custom Banner media type while uploading the files, but it may not be set up with the mandatory fields for it to work.
What are your property Aliases? You've only listed the names and the types. My guess is you haven't got the Image Cropper set up with an alias of umbracoFile, and you should also set up the other media aliases as labels similar to the Image media type.
As per Robert's comment I have updated the \Umbraco\lib\ng-file-upload\ng-file-upload.min.js file(line number 185 for unminified file).
if (h == "Banner") {// my custom media type alias is Banner
var regexp = /(?:\.([^.]+))?$/;
var ext = regexp.exec(a.file.name)[1];
ext = ext.toLowerCase();
var imageExtensions = ["png", "jpeg", "gif","jpg"];
if (imageExtensions.indexOf(ext)>-1) {
h = "Image";
}
var fileExtensions = ["pdf", "doc", "gif", "xls", "xlsx", "odt", "ods", "ppt", "pptx", "txt", "zip", "svg", "csv"];
if (fileExtensions.indexOf(ext) > -1) {
h = "File";
}
console.log(ext);
}
Can someone post an example of how to use the camera, capture the image, preview the image in an image view, compress the image in jpg and upload the bytes to a remote server? The closest I have been able to find is below. We have the camera, and image capture but we need to know how to preview, compress/resize jpg to 640/480px and around 120kb size then upload bytes to a remote server. Thanks to all of you for your help.
http://android-coding.blogspot.com/2010/12/intent-of-mediastoreactionimagecapture.html
Looking at your code there are some things i notice to be wrong:
-[ for the camera functionality ]-
Don't create a file yourself. This is not necessary. Use the ContentResolver.Insert function to give you back a file URI that will contain the picture, just like done here and also take over the isMounted if you want to check if there is external memory present.
You are checking if there's data and then checking if there is a thumbnail. If there's no thumbnail you'll get the full image. That doesn't make sense unless you want to make a thumb of the full version if the thumb is not given back?? Don't you just want to grab the full version or both but not this OR that?
You are retrieving a string value variable to get the URI to the full image? Just save the uri you get from the code in my first point as a property (let's say "myPhotoURI" in the activity class. In the OnActivityResult function that handles your camera intent result just recall that URI and use it as following (Yes, you're seeing it right; i'm not even using the data intent for this just the remembered uri):
Bitmap imageFromCam = MediaStore.Images.Media.GetBitmap(this.ContentResolver, Android.Net.Uri.Parse(myPhotoURI));
To grab an image from the gallery just use the SelectImageFromStorage() function from this question's answer and retrieve the URI of the chosen image in the OnActivityResult check just use:
Android.Net.Uri selectedImageUri = data.ToURI();
That's what worked like a charm for me.
-[sending the data to a webservice ]-
Assuming you're using a WCF or webservice that'll want to receive the image data as a byte array; the approved answer to this question gives a nice example of how to convert your image to an byte array (which is what a WCF webservice wants, anyway)
I think that these directions will get you going.
here is the closest example to date... this brings back Null data when the extra output is used. Still trying to get access to the full image/photo and not a thumbnail.
private void saveFullImage() {
Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture);
string file = System.IO.Path.Combine(Android.OS.Environment.DirectoryDcim.ToString(), "test.jpg");
var outputFileUri = Android.Net.Uri.Parse(file);
intent.PutExtra(Android.Provider.MediaStore.ExtraOutput, outputFileUri);
StartActivityForResult(intent, TAKE_PICTURE);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PICTURE)
{
Uri imageUri = null;
// Check if the result includes a thumbnail Bitmap
if (data != null)
{
if (data.HasExtra("data"))
{
var thumbnail = data.GetParcelableArrayExtra("data");
// TODO Do something with the thumbnail
}
}
else
{
var outputFileUri = data.GetParcelableArrayExtra("outputFileuri");
// TODO Do something with the full image stored
// in outputFileUri
}
}
}