I developed an app with immersion mode for google glass with two activities:
1. Activity_1: Capture image with SurfaceView.
2. Activity_2: View captured image. It works perfect.
Now I need to make app into Live cards. I have seen the demo from github. Still have confused with Live cards usage. Whether we need to create two services for these activities or else have to create one service for start up activity with livecards. Let me suggest how to implement livecards with these two activities.
The reason live cards need a service is because they can run in the background and a service is just a task that can run in the background (whereas an activity is foreground only).
You can use a single service to manage as many live cards as you like:
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
mLiveCard1 = new LiveCard(this, LIVE_CARD_TAG_2);
mLiveCard1.setViews(mView1);
mLiveCard1.publish(LiveCard.PublishMode.SILENT);
mLiveCard2 = new LiveCard(this, LIVE_CARD_TAG_2);
mLiveCard2.setViews(mView2);
mLiveCard2.publish(LiveCard.PublishMode.SILENT);
}
However it sounds like you may just be wanting a single live card at a time, so you may want to set it up so that one live card has an action which unpublishes itself and then publishes a new card.
Related
During WWDC 2019 Apple introduced NSPersistentCloudKitContainer which allows for syncing of CoreData with CloudKit. It is a great addition. In iOS 13 in notes app also user is allowed to to share the entire note "FOLDER" with another user. Given that Apple uses CloudKit for Notes app, I wanted to create something similar to understand how it better works.
Apple creates com.apple.coredata.cloudkit.zone zone and basically syncs all data there into that zone if all setup conditions are met. However there is no guideline when user would like to share data. According to a former WWDC talk, sharing would be possible mainly via creating a CUSTOM ZONE. However the new NSPersistentCloudKitContainer provides no possible way to change the zone for each entity in the CoreData.
I was very happy to have found these
open func record(for managedObjectID: NSManagedObjectID) -> CKRecord?
open func records(for managedObjectIDs: [NSManagedObjectID]) -> [NSManagedObjectID : CKRecord]
open func recordID(for managedObjectID: NSManagedObjectID) -> CKRecordID?
open func recordIDs(for managedObjectIDs: [NSManagedObjectID]) -> [NSManagedObjectID : CKRecordID]
as they gave this impression that the container calls this methods to retrieve the CKRecord and hence a point to modify informations such as zone etc. but after the setup I realized when I add a new entity to my CoreData, these functions even though when overrides are not called.
My question in short is: how to take controll of how NSPersistentCloudKitContainer manages which record belongs to which zone other than com.apple.coredata.cloudkit.zone
I've set up a simple QnA bot which is linked to a QnA service. Within the QnA service I have set up some questions which have follow up prompts(Dependents) e.g. how do I get to a campus, via bus, train etc. see image in link, within the Qna maker testing function you can just click a button called enable mutli-turn which provides functional buttons to inform you of what can/should be asked next via the dependents of the answer See image in link.
However when used within a channel/in the emulator nothing of the like appears see image, which is a bit odd. And obviously I want to implement such functionality in to the bot as it makes life so much easier for the users.
I am new to the whole bot thing(I started last month), so I have a browsed the internet to see what I could find but I could not see anything out side of writing the questions within the bot it self, see Microsofts documentation, which makes using QnA maker pretty much pointless.
What I think I need to do is intercept the message from QnA maker as it replies to the user, look at the Json received to find if has any dependents then run a different dialog, which gets the contextual dependents names and runs a simple for loop generating cards for each dependents, then send the message to the user with the generated cards, however I'm not sure how to intercept the Json and look for any dependents, or there is a button the I need to click within azure which just does it.
There is this experimental sample that has been released by the Bot Framework team which demonstrates how to handle follow-up prompts.
You can download it (you will have to download the whole repo) then plug in your details to the appsettings.json file and you should be able to test it using the Bot Framework Emulator - these were the only steps that I had to perform.
The key part is this method which checks to see if the result contains any prompts and returns the response accordingly - it is called inside the FuctionDialog.
If you're only ever going to be implementing a single level of prompts i.e. you have a question which shows prompts and when you click on one of these prompts it will display an answer rather than taking you to another prompt, then it is possible to take the guts of the logic from the ProcessAsync method (checking for prompts) along with the required classes from the Models folder and the CardHelper class and get this to work in your existing application - you won't have to worry about the QnABotState because you'll only be going a single level deep so you don't need to track where you are in the series of prompts. e.g.
var query = inputActivity.Text;
var qnaResult = await _qnaService.QueryQnAServiceAsync(query, new QnABotState());
var qnaAnswer = qnaResult[0].Answer;
var prompts = qnaResult[0].Context?.Prompts;
if (prompts == null || prompts.Length < 1)
{
outputActivity = MessageFactory.Text(qnaAnswer);
}
else
{
outputActivity = CardHelper.GetHeroCard(qnaAnswer, prompts);
}
await turnContext.SendActivityAsync(outputActivity);
Could someone please advice where do we add this code mentioned above? I am a rookie, have very basic knowledge about programming. Using visual studio with C# for this. How and where do I add this code to make it work? I am also not diving too deep. Just trying to make some simple logic where a user clicks on a few follow up prompts and is taken to the required information. Would really appreciate if someone could help. Thanks
First picture shows the starting follow up prompt.
Second picture that follows the first followup prompt
Basically I want to display the current track on a website.
I already searched quite a bit for a possibility to get notified when player state (play/pause, track, current position) changes.
My question:
Is it possible to get notified (socket, hook call) or is the only possibility I have to call the Web API like every second and fetch the state?
I fear that I'm running into rate limits when multiple users connect their accounts and display the current track.
Nope, there's still no way to do that. To achieve what you'd like, you need to pool the Spotify API continuously.
You can however use the Spotify SDK that you can pass a function to be executed on playback state change. The SDK is incompatible with a few platforms (see supported browsers), but for those you could catch the SDK initialization error and then switch to continuous polling via the API. You will have a lot fewer requests then.
A second option would be to only update the currently playing song after the last song should have ended. When getting the playback state for the currently playing song, you could use the field duration_ms and progress_ms to calculate the remaining time of the song. Then schedule another API requests for when the song should have ended and you're good. Whether that's a good strategy for your use case or not depends on the type of playback and how often the playback changes in your app.
I hope I could help!
As of now, it seems to be possible to receive player state events with a listener:
https://developer.spotify.com/documentation/web-playback-sdk/guide/#playback-information-display
I haven't tested the Web version, I'm currently using the analogous Android APIs, and Android's seems to work for play/pause change and track change (but not for position change)
I come from an electronics background, with a project whereby I'd like to be able to obtain various information about the state of the desktop player, eg
Current track name
Current track artist
Position in song
Play/pause status
Is there an active API or other method which will allow me to obtain this information and get it out of the desktop app itself, such that I might be able to send that information out via a COM port?
Thanks in advance.
You could use my .NET Library SpotifyAPI .NET
It combines the spotify-local and spotify-web API.
Also, it provides all your required information and is simple to use.
Small example:
SpotifyLocalAPIClass spotify = new SpotifyLocalAPIClass();
if(!spotify.Connect())
return;
SpotifyMusicHandler mh = spotify.GetMusicHandler();
SpotifyEventHandler eh = spotify.GetEventHandler();
Console.WriteLine(mh.GetCurrentTrack().GetTrackName());
I am building an app that needs to know if a track is playable in the user's region.
It's easy to check the basic territorial restrictions of a track using the Metadata API. However, I am encountering tracks that the Metadata API says are out of my region, but are auto-linked to versions of the same track that aren't region locked. ie. Metadata says I can't play a track, but as far as the user is concerned, Spotify can play that track.
Here's an example:
'Sweet Unrest' by Apparat # spotify:track:4H4h3ulzjGVox14GHiCEoo
I am in the UK (territory code GB)
The lookup link is http://ws.spotify.com/lookup/1/.json?uri=spotify:track:4H4h3ulzjGVox14GHiCEoo
There is no GB code in the resulting territories string, so in theory, I should not be able to play the track. However, in the main Spotify player, I can see that it is auto linked to spotify:track:11S6TQybYumAnNApugZWSJ which is playable in my region. If I paste the supposedly unplayable track's URI into the top left Spotify search box, it plays.
Is there an API based way to check for tracks like this?
You can detect whether a track is playable or not using an undocumented property of each track: data.availableForPlayback
Track.fromURI("spotify:track:XXX", function(track) {
alert(track.data.availableForPlayback);
});
If you run the code above, you should get a True/False that does what you're after.
Unfortunately not, not at this time. The linking is actually done by the client itself rather than any of our backend services, so none of our APIs have this information.