Is there a way to support .3gp format in AVPlayer? It does not seem to play it, while it plays any other format e.g., .mov, .mp4.
let player = AVPlayer(url: videoURL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
Related
I want to capture an Image and a Video using the CameraX library. By following the documentation i have no problem implementing the preview and the capture use cases. The code i use is the following.
private fun startCamera() {
cameraProviderFuture = ProcessCameraProvider.getInstance(this)
cameraProviderFuture.addListener({ setUpCamera() }, cameraExecutor)
}
private fun setUpCamera() {
cameraProvider = cameraProviderFuture.get()
bindPreview()
}
private fun bindPreview() {
preview = Preview.Builder().build().also {
it.setSurfaceProvider(binding.cameraPreview.surfaceProvider)
}
imageCapture = ImageCapture.Builder()
.setFlashMode(flashMode)
.setCaptureMode(CAPTURE_MODE_MAXIMIZE_QUALITY)
.build()
videoCapture = ...
bindCamera()
}
private fun bindCamera() {
cameraSelector = selectExternalOrBestCamera()
cameraProvider.unbindAll()
camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageCapture, videoCapture)
Now, let's say that i have locked my device orientation from the menu panel. So if i rotate de device, the applications do not rotate at all. In that case, if a capture an Image, the captured image which i save and i want to send to a Server is rotated by 90 degrees,, which is reasonable since i rotated the device and capture a photo.
As i can see, in other applications (like Whatsapp) the same senario does not happen since they show the preview image correctly rotated after the capture. How can i solve that issue?
So finally i found the solution.
val rotation = display?.rotation ?: Surface.ROTATION_0
val isLandscape = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
imageCapture = ImageCapture.Builder()
.setFlashMode(flashMode)
.setCaptureMode(CAPTURE_MODE_MAXIMIZE_QUALITY)
.setTargetRotation(rotation)
.setTargetResolution(
if (isLandscape)
Size(1920, 1080)
else
Size(1080, 1920)
)
.build()
That gives me the preview image that i capture in the desired orientation
I need to create thumbnail starting from a WebP image but ImageIO doesn't support this format. Are there any library that allow me to do something like this ?
String format = getImageFormat(imageFile);
Iterator readers = ImageIO.getImageReadersByFormatName(format);
// rescaling the image
BufferedImage bi = loadImageRescalingIfNeeded(imageFile, metadata,...);
//resample if needed
bi = resampleImageIfNeeded(bi, thumbWidth, thumbHeight);
// rotate if degree > 0
bi = rotateBufferedImage(bi, degree);
// create jpeg in output
try (ImageOutputStream imageOut = ImageIO.createImageOutputStream(fileOutputStream)){
try {
ImageWriter writer = ImageIO.getImageWritersBySuffix("jpeg").next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);
writer.setOutput(imageOut);
writer.write(null, new IIOImage(bi, null, metadata), iwp);
} catch (Exception e) {...}
....}
I have profile photo of users stored in Firebase and I want to know how I can create a marker with the user's profile photo with an orange border.
I tried some code from the internet and it works but the measurements seem to be wrong and I don't know what I'm doing wrong.
The code I used:
fun setMarkerPhoto(user:User, location: Location){
var bitmapFinal : Bitmap?
if(hasProfilePhoto){
/*val options = RequestOptions()
options.centerCrop()*/
Glide.with(this)
.asBitmap()
/*.apply(options)*/
.centerCrop()
.load(user.image)
.into(object : CustomTarget<Bitmap>(){
override fun onResourceReady(resource: Bitmap, transition: com.bumptech.glide.request.transition.Transition<in Bitmap>?) {
bitmapFinal = createUserBitmapFinal(resource)
markerOptions
.position(LatLng(location!!.latitude, location!!.longitude))
.title("Current Location")
.snippet(address)
.icon(BitmapDescriptorFactory.fromBitmap(bitmapFinal))
mCurrentMarker = googleMap.addMarker(markerOptions)
}
override fun onLoadCleared(placeholder: Drawable?) {
TODO("Not yet implemented")
}
})
}else{
markerOptions
.position(LatLng(mLastLocation!!.latitude, mLastLocation!!.longitude))
.title("Current Location")
.snippet(address)
.icon(BitmapDescriptorFactory.fromBitmap(smallMarker))
mCurrentMarker = googleMap.addMarker(markerOptions)
}
}
private fun createUserBitmapFinal(bitmapInicial: Bitmap?): Bitmap? {
var result: Bitmap? = null
try {
result = Bitmap.createBitmap(150,150, Bitmap.Config.ARGB_8888) //change the size of the placeholder
result.eraseColor(Color.TRANSPARENT)
val canvas = Canvas(result)
val drawable: Drawable = resources.getDrawable(R.drawable.ic_pickup)
drawable.setBounds(0, 0, 150,150) //change the size of the placeholder, but you need to maintain the same proportion of the first line
drawable.draw(canvas)
val roundPaint = Paint(Paint.ANTI_ALIAS_FLAG)
val bitmapRect = RectF()
canvas.save()
if (bitmapInicial != null) {
val shader =
BitmapShader(bitmapInicial, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
val matrix = Matrix()
val scale: Float = 200 / bitmapInicial.width.toFloat() //reduce or augment here change the size of the original bitmap inside the placehoder.
// But you need to adjust the line bitmapRect with the same proportion
matrix.postTranslate(5f, 5f)
matrix.postScale(scale, scale)
roundPaint.shader = shader
shader.setLocalMatrix(matrix)
bitmapRect[10f, 10f, 104f+10f]=104f+10f //change here too to change the size
canvas.drawRoundRect(bitmapRect, 56f, 56f, roundPaint)
}
I didn't really understand how to perfectly fit the bitmap image inside the placeholder. My marker looked like this:
also the image wasn't being center cropped even though I mentioned that it should be in the code, where it says Glide.centerCrop()
Also, I'm using GeoFire to display markers of users in a specified radius of the user and for now I can display a simple marker but I want the marker to have that user's profile photo too! How can I do it?
GeoFire Code:
val geoQuery: GeoQuery = geoFire.queryAtLocation(GeoLocation(location.latitude, location.longitude), 0.5)
geoQuery.addGeoQueryEventListener(object : GeoQueryEventListener {
override fun onKeyEntered(key: String, location: GeoLocation) {
println(String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude))
Log.i("key entered","User found around you")
val aroundYou = LatLng(location.latitude, location.longitude)
if (markerList != null) {
for (marker in markerList) {
marker.remove()
}
}
otherMarkerOptions
.position(aroundYou)
.title("Current Location")
//.snippet(address)
.icon(BitmapDescriptorFactory.fromBitmap(smallMarker)) //This is a simple marker but i want it to have the user's profile photo
markerList.add(googleMap.addMarker(otherMarkerOptions))
//}
}
Thank you in advance
Edit:
In the line: val drawable: Drawable = resources.getDrawable(R.drawable.ic_pickup)
It's this png:
I want to insert the profile photo of the user on that drawable file and if the user doesn't have a profile photo then only the drawable photo will be visible.
You get the code to transform the bitmap from my code in another question in StrackOverflow. As I mentioned there, I can´t teste the code because i´m only working with flutter right now.
But looking ate your code I might try this:
Add this function:
fun dp(value: Float): Int {
return if (value == 0f) {
0
} else Math.ceil(resources.displayMetrics.density * value.toDouble()).toInt()
}
in your lines:
result = Bitmap.createBitmap(150,150, Bitmap.Config.ARGB_8888);
drawable.setBounds(0, 0, 150,150);
change to:
result = Bitmap.createBitmap(dp(62f), dp(76f), Bitmap.Config.ARGB_8888);
drawable.setBounds(0, 0, dp(150f), dp(150f)) ;
let me know the results.
I have set an animated image in CollectionView cell but I
didSelectItemAt method call but how can solve animated image this hide
issue please see this video URL.
let data:[UIImage] = images![indexPath.row] as! [UIImage]
cell.ivImage.animationImages = data
cell.ivImage.animationDuration = 1.0
cell.ivImage.startAnimating()
stickerCV.allowsSelection = false
Collection Cell
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
tap.accessibilityLabel = "\(indexPath.row),\(indexPath.section)"
tap.numberOfTapsRequired = 1
cell.ivSitcker.isUserInteractionEnabled = true
cell.ivSitcker.addGestureRecognizer(tap)
Tap Gesture
#objc func handleTap(_ sender: UITapGestureRecognizer) {
let data = sender.accessibilityLabel?.components(separatedBy: ",")
let index = Int(data![0])
let section = Int(data![1])
selectedIndex = index!
let sectionData = AppData.sharedInstance.arrOfStickers[selectedStickerIndex]
self.strSelectedSticker = sectionData[index!]
self.createSticker(image: self.strSelectedSticker[0])
self.selectedIndex = index!
self.stickerCV.reloadData()
}
im trying to change the marker or pin image to the one i download from firebase with alamofireimage. Please i need help
this is my code:
let coordinates = CLLocationCoordinate2D(latitude: milatitud!, longitude: milongitud!)
let annotation = MKPointAnnotation()
annotation.coordinate = coordinates
annotation.title = "JuanJo"
self.map.addAnnotation(annotation)
//print ("4444444444")
for annotation: MKAnnotation in self.map.annotations {
let anView = self.map.view(for: annotation)
if (anView != nil)
{
let url = URL(string: link!)
self.imagen.af_setImage(withURL: url!, placeholderImage: UIImage(named: "usuarioprevia.jpeg"), filter: CircleFilter(), imageTransition: .crossDissolve(0.5), runImageTransitionIfCached: true, completion: nil)
anView?.image = "image downloaded from firebase with alamofireimage"
}
i dont know the last part how to set it = for displaying the image, also i need to resize it. Please help