I'm using AVPlayerViewController in order to play an HLS file, however the start time is always 00:00 and the end time is the duration of the event from the HLS manifest.
Instead I would wish to display the start time of the event and the end time of the event.
I found that can be used: AVKitMetadataIdentifierExactStartDate / AVKitMetadataIdentifierExactEndDate
But looks like when I create an AVMutableMetadataItem and I try to assign as identifier the AVKitMetadataIdentifierExactStartDate it doesn't exist. So I'm kind of stuck.
Anyone has any idea?
After few days of researches, I found that this can be achieved creating a AVMutableMetadataItem, assigning them as identifier an AVMetadataIdentifier(AVKitMetadataIdentifierExactStartDate) then as value you can just add the start time as date and cast everything as NSCopying & NSObjectProtocol.
Once you setup both properties you can append to the player.currentItem.externalMetadatas the new metadataItems that you just created as array of metadataItems.
Full example below:
//Add start date
let item = AVMutableMetadataItem()
item.identifier = AVMetadataIdentifier(AVKitMetadataIdentifierExactStartDate)
item.value = startDate as? NSCopying & NSObjectProtocol
let metadataItem = item.copy() as! AVMetadataItem
//Add start date
let endTimeItem = AVMutableMetadataItem()
endTimeItem.identifier = AVMetadataIdentifier(AVKitMetadataIdentifierExactEndDate)
endTimeItem.value = endDate as? NSCopying & NSObjectProtocol
let endTimeMetadataItem = endTimeItem.copy() as! AVMetadataItem
var metadataItems = [AVMetdataItem]()
metadataItems.append(metadataItem)
metadataItems.append(endTimeMetadataItem)
self.player.currentItem?.externalMetadata = metadataItems
Related
Hello i get my date from Datepicker that gets saved to a string then uploaded to Firebase. The string is then recieved to the phone. The problem is that i want to convert this string to NSDate when i retrieve it.
This is how i get a string from datepicker
func datePickerChanged(datePicker:UIDatePicker){
var dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = NSDateFormatterStyle.ShortStyle
dateFormatter.timeStyle = NSDateFormatterStyle.ShortStyle
var strDateFrom = dateFormatter.stringFromDate(datePicker.date)
fromDate = strDateFrom
print(fromDate)}
When i retrieve the date i get it as a string this is the print
print(self.membershipActiveTo)
And this is the print log
5/11/16, 2:35 PM
And below is the line of code i have tried to convert to string but it only returns nil
let strDate = self.membershipActiveTo // "2015-10-06T15:42:34Z"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm"
print ( dateFormatter.dateFromString( strDate ) )
There are things to consider when working with dates and one of them is how to store the date in a consistent format that can be easily worked with for different uses. In your case, you may want to sort by date and if the data is stored like this
5/11/16, 2:35 PM
It's not going to be sortable. So, a different format is needed and here's one possible example
20160511143500
Here's some code to manipulate dates:
Write a nicely formatted date to Firebase
let d = NSDate()
//create a custom date string & save in firebase
let dateFormatterCustom = NSDateFormatter()
dateFormatterCustom.dateFormat = "yyyyMMddhhmmss"
let customDateString = dateFormatterCustom.stringFromDate(d)
print(customDateString) //prints "20160511023500" just for testing
let timesRef = self.myRootRef.childByAppendingPath("time_test")
let thisTimeRef = timesRef.childByAutoId()
let timeChildRef = thisTimeRef.childByAppendingPath("timestamp")
timeChildRef.setValue(customDateString)
Firebase now has this
time_test
-KFerAcANQv4pN1Pp4yW
timestamp: "20160418033309"
Then to read in from Firebase:
let timesRef = self.myRootRef.childByAppendingPath("time_test")
timesRef.observeEventType(.ChildAdded, withBlock: { snapshot in
let timeStamp = snapshot.value.objectForKey("timestamp") as! String
print(timeStamp) //still looks like 20160418033309
let shortDateString = self.timeStampToDateString(timeStamp)
print(shortDateString) //prints 4/18/16, 3:33 AM
})
and the function that converts the timestamp style string to a human readable one
func timeStampToDateString(stamp: String) -> String {
//create a custom date string & create a date object from it
let dateFormatterCustom = NSDateFormatter()
dateFormatterCustom.locale = NSLocale(localeIdentifier: "US_en")
dateFormatterCustom.dateFormat = "yyyyMMddhhmmss"
let d = dateFormatterCustom.dateFromString(stamp)!
//create a short date style string and format the string
let dateFormatterShortStyle = NSDateFormatter()
dateFormatterShortStyle.dateStyle = NSDateFormatterStyle.ShortStyle
dateFormatterShortStyle.timeStyle = NSDateFormatterStyle.ShortStyle
let dateString = dateFormatterShortStyle.stringFromDate(d)
return dateString
}
There's a lot of extra code in this example so it could be shortened considerably but I wanted to leave in all of the steps.
Is it possible to create a date only field in XPages? I have tried the following in the querySaveDocument event but the field still ends up with a time portion of 00:00:00
var notesDoc:NotesDocument = document1.getDocument();
var dt:NotesDateTime = session.createDateTime(#Today());
dt.setAnyTime();
notesDoc.replaceItemValue("MyDateField", dt);
It is not completely clear what you are trying achieve.
You can put an EditBox component on your XPage, then go to the "Data" tab. From there you can change the formatting from String to Date. More options should appear on how to format the date in the field. It will handle passing the date to the back end document.
If it is you want to write directly to the back end document, then here is a page listing samples on working with NotesDateTime.
http://www-10.lotus.com/ldd/ddwiki.nsf/dx/NotesDateTime_sample_JavaScript_code_for_XPages
Here is code by Sven:
ndt = session.createDateTime(ndt.getDateOnly());
item.setDateTimeValue(ndt);
error in date items, daylight Saving
Update:
I had to do the same thing and found out that it's working this way in Java agent in 8.5.2FP3:
DateTime dt = session.createDateTime(new java.util.Date());
dt.setAnyTime();
doc.appendItemValue("DT", dt);
I'm using core data with a single NSManagedObjectContext and am doing all operation for core data on the main thread. The new and old row given in error description are identical and am at hoping that someone can explain why am getting a merge conflict. Setting merge policy to overwrite is causing the app to run into high CPU in simulator and become unresponsive.
However, when I try to update managed objects in one entity, the app crashes with following error,
NSMergeConflict (0x7144390) for NSManagedObject (0x7225db0) with objectID '0x721c0a0 <x-coredata://94349DC2-C441-4102-9C65-60737E940135/Locations/p1>' with oldVersion = 2 and newVersion = 3 and
old cached row = {\n AccountInfo = \"0x721bae0 <x-coredata://94349DC2-C441-4102-9C65-60737E940135/Account/p1>\";\n City = \"<null>\";\n Country = \"Russian Federation\";\n EntryStatusId = \"<null>\";\n ExitStatusId = \"<null>\";\n IsCorporateLocation = 1;\n IsVisible = 1;\n Latitude = 50;\n LocationId = 10003;\n Longitude = 40;\n Name = \"Test Location\";\n Radius = 304;\n State = \"Province of Voronezh\";\n Street = \"<null>\";\n Units = METER;\n Zip = \"<null>\";\n} and
new database row = {\n AccountInfo = \"0x7144560 <x-coredata://94349DC2-C441-4102-9C65-60737E940135/Account/p1>\";\n City = \"<null>\";\n Country = \"Russian Federation\";\n EntryStatusId = \"<null>\";\n ExitStatusId = \"<null>\";\n IsCorporateLocation = 1;\n IsVisible = 1;\n Latitude = 50;\n LocationId = 10003;\n Longitude = 40;\n Name = \"Test Location\";\n Radius = 304;\n State = \"Province of Voronezh\";\n Street = \"<null>\";\n Units = METER;\n Zip = \"<null>\";\n}
Update: The error doesn't happen if I save the MOC after updating every object but happens if I update all the objects and then save MOC. Anyone knows why this is happening?
The error suggest that you do actually have two separate contexts. You only get a merge when you have two or more context writing to the same store.
I would suggest logging the context before every save, everywhere you perform a save to make certain you only have one active context.
It is posible to let the Core Data deals with this conflicts automatically instead of throw an Exception. See this post: http://pauloliveira.net/tech/core-data-merging-conflicts
I realized I have this with all combo box. I want it to have a default value so I tried...
TimeField field = new TimeField();
field.setFormat(DateTimeFormat.getFormat("HH:mm"));
field.setRawValue("10:00");
But when I open the section, the value does not get set. It is still blank.
I m found the solution. I used following format its woks.
private TimeField fromTime = new TimeField();
fromTime.setFormat(DateTimeFormat.getFormat("HH:mm"));
fromTime.setIncrement(1);
Time time = new Time();
time.setText("00:00");
fromTime.setValue(time);
fromTime.setTriggerAction(TriggerAction.ALL);
toolbar.add(fromTime);
I'm using the following code to create an All Day Event in a SharePoint calendar:
newitem = listobject.Items.Add()
guid = System.Guid.NewGuid()
newitem["Name"] = "All Day Event " + guid.ToString()
newitem["Title"] = "All Day Event " + guid.ToString()
newitem["Start Time"] = System.DateTime.Now.Date
newitem["End Time"] = System.DateTime.Now.Date
newitem["Description"] = "Created by Automation Script"
newitem["Location"] = "Location " + guid.ToString()
newitem["UID"] = guid
newitem["All Day Event"] = 1
newitem.Update()
print newitem["Created"]
However, when I query for the Created date of the created item (as in the last line ), it gives me the time in UTC. But in case of a Normal event or a recurrent event it gives me the local time. I tried to find the Kind property of the DateTime object, but it is set to Unspecified. The same problem occurs even if an All Day Event is created through the SharePoint site (manually). So I came to a conclusion that there is nothing wrong in the code. Please help me.
See
SO SharePoint - all day events behave differently in CAML query