I'm creating a kotlin app. I have an issue with mediaMetadataCompat. Maybe I have to put data to extras? I put data like this
audios = allAudios!!.map { audio ->
MediaMetadataCompat.Builder()
.putString(METADATA_KEY_WRITER, audio.writer._id)
.putString(METADATA_KEY_ARTIST, audio.writer.name)
.putString(METADATA_KEY_DISPLAY_SUBTITLE, audio.writer.name)
.putString(METADATA_KEY_MEDIA_ID, audio._id)
.putString(METADATA_KEY_TITLE, audio.title)
.putString(METADATA_KEY_DISPLAY_TITLE, audio.title)
.putString(METADATA_KEY_DISPLAY_ICON_URI, audio.writer.image)
.putString(METADATA_KEY_DATE, audio.createdAt)
.putString(METADATA_KEY_MEDIA_URI, audio.filePath)
.putString(METADATA_KEY_DISPLAY_DESCRIPTION, audio.description)
.build()
}
Get it like this
fun MediaMetadataCompat.toAudio(): Audio? {
return let {
Audio(
_id = it.description.mediaId ?: "",
title = it.description.title.toString(),
filePath = it.description.mediaUri.toString(),
description = it.description.description.toString(),
writer = User(
_id = it.description.extras?.getString("writerId").toString(),
name = it.description.subtitle.toString(),
image = it.description.iconUri.toString()
),
tags = listOf("Shit"),
listened = 1,
language = "en",
isForKids = false,
duration = 70,
createdAt = "2020:01:01"
)
}
}
It only gives my title, icon_uri, media_uri and media_id
Sharing a small part of my code:
Below is building object of MediaMetaDataCompat. I am adding couple of data there and have used in different parts of app.
var media = MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, data.id.toString())
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, data.artist_name)
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, data.title)
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_URI, data.audio_path)
.putString(MediaMetadataCompat.METADATA_KEY_DATE, data.track_year)
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI, data.image_path)
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, data.duration.toLong())
.build()
mediaItem is object of MediaMetadataCompat and that is how I am getting values of the fields which was added to object.
mediaItem is object of MediaMetadataCompat
var artist = mediaItem.bundle.getString(MediaMetadataCompat.METADATA_KEY_ARTIST)!!
var title = mediaItem.bundle.getString(MediaMetadataCompat.METADATA_KEY_TITLE)!!
var duration = mediaItem.bundle.getLong(MediaMetadataCompat.METADATA_KEY_DURATION)!!
var icon = mediaItem.bundle.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI)!!
Related
I tried to convert a java file to kotlin file but i'm getting this error : An annotation argument must be a compile-time constant
#StringDef(
BillingEnum.ALL,
BillingEnum.PAID,
BillingEnum.PENDING,
BillingEnum.OVERDUE,
BillingEnum.OPEN,
BillingEnum.DELETED
)
annotation class BillingEnum {
companion object {
var ALL = ""
var PAID = "paid"
var PENDING = "pending"
var OVERDUE = "overdue"
var OPEN = "open"
var DELETED = "deleted"
}
}
Before it looked like this:
#StringDef({
BillingEnum.ALL,
BillingEnum.PAID,
BillingEnum.PENDING,
BillingEnum.OVERDUE,
BillingEnum.OPEN,
BillingEnum.DELETED
})
public #interface BillingEnum {
String ALL = "";
String PAID = "paid";
String PENDING = "pending";
String OVERDUE = "overdue";
String OPEN = "open";
String DELETED = "deleted";
}
You must write
annotation class BillingEnum {
companion object {
const val ALL = ""
const val PAID = "paid"
const val PENDING = "pending"
const val OVERDUE = "overdue"
const val OPEN = "open"
const val DELETED = "deleted"
}
}
I am using following code to fetch video file paths that is available on Android offical documentation..
fun getAllVideosPath(context: Context) {
val videoList = mutableListOf<VideoInfo>()
val collection =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaStore.Video.Media.getContentUri(
MediaStore.VOLUME_EXTERNAL
)
} else {
MediaStore.Video.Media.EXTERNAL_CONTENT_URI
}
val projection = arrayOf(
MediaStore.Video.Media._ID,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.DURATION,
MediaStore.Video.Media.SIZE
)
// Show only videos that are at least 5 minutes in duration.
val selection = "${MediaStore.Video.Media.DURATION} >= ?"
val selectionArgs = arrayOf(
TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS).toString()
)
// Display videos in alphabetical order based on their display name.
val sortOrder = "${MediaStore.Video.Media.DISPLAY_NAME} ASC"
val query =
context.contentResolver.query(collection, projection, selection, selectionArgs, sortOrder)
query?.use { cursor ->
// Cache column indices.
val idColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID)
val nameColumn =
cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME)
val durationColumn =
cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)
val sizeColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE)
Log.i("CursorSize", "${cursor.position}")
while (cursor.moveToNext()) {
// Get values of columns for a given video.
val id = cursor.getLong(idColumn)
val name = cursor.getString(nameColumn)
val duration = cursor.getInt(durationColumn)
val size = cursor.getInt(sizeColumn)
val contentUri: Uri = ContentUris.withAppendedId(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
id
)
// Stores column values and the contentUri in a local object
// that represents the media file.
videoList += VideoInfo(contentUri, name, duration, size)
Log.i("asdsa", name)
}
}
}
I am getting file paths on android mobile using this Up to Android 12 but unable to get paths on Andorid tv. Is i am missing some thing or there is some other way to get file paths on android tv...?
How to detect, in a fixed length file, the same record type?
BeanIO dected only first record header without the others two documents.
What I would like is to obtain wrapper class with the three documents and their item codes.
This is an example of fixed length txt file:
Unknown record
Unknown record
RH20210607A
RDitem1
RDitem2
Unknown record
RH20210607B
RDitem2
RDitem3
Unknown record
Unknown record
Unknown record
RH20210607C
RDitem1
RDitem4
RDitem5
I want to detect the header (RH) and detail (RD) record.
I designed a group list with another group for each subgroup.
Top group class:
#Group(name = "fixedFile")
public class ListDocumentWrapper {
#Group(minOccurs=1, type=Document.class, collection = List.class)
List<Document> documentList;
}
Subgroup class:
#Data
public class Document{
#Record(order = 1, minOccurs=1, maxOccurs=1)
private RH recordHeader;
#Record(order = 2, minOccurs=1, type=RD.class, collection = List.class)
private List<RD> recordDetails;
}
Single record class:
#Data
#Record
public class RH{
#Field(ordinal = 0, required = true, length = 2, align = Align.LEFT, rid = true, literal = "RH")
private String recordType;
#Field(ordinal = 1, required = true, length=8, format = "yyyyMMdd")
private LocalDate documentDate;
#Field(ordinal = 2, required = true, length = 1, padding = ' ', align = Align.LEFT)
private String documentCode;
}
#Data
#Record
public class RD{
#Field(ordinal = 0, required = true, length = 2, align = Align.LEFT, rid = true, literal = "RD")
private String recordType;
#Field(ordinal = 1, required = true, length = 5, padding = ' ', align = Align.LEFT)
private String itemCode;
}
Init of BeanReader:
// create a StreamFactory
StreamFactory factory = StreamFactory.newInstance();
// load the mapping file
String streamBuilderName = "fixedFile";
factory.define(
new StreamBuilder(streamBuilderName)
.format("fixedlength")
.parser(new FixedLengthParserBuilder())
.ignoreUnidentifiedRecords()
.addGroup(ListDocumentWrapper.class)
);
BeanReader beanReader = factory.createReader(streamBuilderName, aFileReader, Locale.ITALIAN);
Thanks for help
I didn't find the right solution, but I found a workaround.
The desire is to make a single read and get a list of document
This is the workaround.
First I didn't understand that beanReader.read() extract the first element of stream. So it's no necessary to create ListDocumentWrapper but read all Document with a simple while loop.
This is the extract of code:
List<Document> documentList = new ArrayList<>();
Document documentMessage = null;
int documentIndex = 0;
while ((documentMessage = (Document) beanReader.read()) != null) {
// process the documentMessage...
log.debug("Reading documentMessage ["+documentIndex+"]... => " + documentMessage);
documentList.add(documentMessage);
documentIndex++;
}
I am getting response from server in JSONArray format. I am not able to retrieve the contents of array also my JSONArray has no Square brackets.
I am passing the response in php as json_encode($array) in server side
response {
community = “worker”
communitystr = "<null>";
workspace = abs;
email = "<null>";
admin = false;
persona = "<null>";
userinfo = {
info = {
contact1 = {
firstname = “jon”;
lastname = “Doe”
phone = “9885678905”;
objectname = contact;
id = 9;
};
event1 = {
eventname = “party”;
description = "";
order = 6;
id = 4;
objectname = events;
};
files = {
filename = “sample”;
description = "";
order = 11;
id = 11;
objectname = files;
};
};
};
};
I checked many links and all have used JSONObject(). But same is not working for me.
How do I get each values in this JSON Response ?
You have to use
: instead of =
, instead of ;
...
Watch out following format:
{
"Herausgeber": "Xema",
"Nummer": "1234-5678-9012-3456",
"Deckung": 2e+6,
"Waehrung": "EURO",
"Inhaber":
{
"Name": "Mustermann",
"Vorname": "Max",
"maennlich": true,
"Hobbys": [ "Reiten", "Golfen", "Lesen" ],
"Alter": 42,
"Kinder": [],
"Partner": null
}
}
Your code seems like to be more JavaScript-Object like :-)
Your response is not valid JSON object.
You can validate the JSON via some online tool, like http://jsonlint.com/
Full specification can be found in RFC 7159 https://www.rfc-editor.org/rfc/rfc7159.
Basically you should look how to encode the values into JSON format in correct way. For that you can refer to PHP Array to JSON Array using json_encode();
I am attempting to get the items and some of the related information from a Purchase Order with SuiteTalk. I am able to get the desired Purchase Orders with TransactionSearch using the following in Scala:
val transactionSearch = new TransactionSearch
val search = new TransactionSearchBasic
...
search.setLastModifiedDate(searchLastModified) //Gets POs modified in the last 10 minutes
transactionSearch.setBasic(search)
val result = port.search(transactionSearch)
I am able to cast each result to a record as an instance of the PurchaseOrder class.
if (result.getStatus().isIsSuccess()) {
println("Transactions: " + result.getTotalRecords)
for (i <- 0 until result.getTotalRecords) {
try {
val record = result.getRecordList.getRecord.get(i).asInstanceOf[PurchaseOrder]
record.get<...>
}
catch {...}
}
}
From here I am able to use the getters to access the individual fields, except for the ItemList.
I can see in the NetSuite web interface that there are items attached to the Purchase Orders. However using getItemList on the result record is always returning a null response.
Any thoughts?
I think you have not used search preferences and that is why you are not able to fetch purchase order line items. You will have to use following search preferences in your code -
SearchPreferences prefrence = new SearchPreferences();
prefrence.bodyFieldsOnly = false;
_service.searchPreferences = prefrence;
Following is working example using above preferences -
private void SearchPurchaseOrderByID(string strPurchaseOrderId)
{
TransactionSearch tranSearch = new TransactionSearch();
TransactionSearchBasic tranSearchBasic = new TransactionSearchBasic();
RecordRef poRef = new RecordRef();
poRef.internalId = strPurchaseOrderId;
poRef.type = RecordType.purchaseOrder;
poRef.typeSpecified = true;
RecordRef[] poRefs = new RecordRef[1];
poRefs[0] = poRef;
SearchMultiSelectField poID = new SearchMultiSelectField();
poID.searchValue = poRefs;
poID.#operator = SearchMultiSelectFieldOperator.anyOf;
poID.operatorSpecified = true;
tranSearchBasic.internalId = poID;
tranSearch.basic = tranSearchBasic;
InitService();
SearchResult results = _service.search(tranSearch);
if (results.status.isSuccess && results.status.isSuccessSpecified)
{
Record[] poRecords = results.recordList;
PurchaseOrder purchaseOrder = (PurchaseOrder)poRecords[0];
PurchaseOrderItemList poItemList = purchaseOrder.itemList;
PurchaseOrderItem[] poItems = poItemList.item;
if (poItems != null && poItems.Length > 0)
{
for (var i = 0; i < poItems.Length; i++)
{
Console.WriteLine("Item Line On PO = " + poItems[i].line);
Console.WriteLine("Item Quantity = " + poItems[i].quantity);
Console.WriteLine("Item Descrition = " + poItems[i].description);
}
}
}
}