How do I send metadata from ExoPlayer to bluetooth? - bluetooth

I'm trying to send fixed metadata through bluetooth on my radio app, basically I would put the radio name as title, and the radio slogan as subtitle, so there isn't anything dynamic involved.
I have tried searching for other answers on StackOverflow but they're related to ICY streams or getting the metadata from ExoPlayer itself.
The stream itself provides the metadata when listening directly through FM or a stream player (for example, VLC), but it fails to display when going through my app.
This is my code, from what I've managed to understand I should send the metadata inside the brackets after 'addMetadataOutput'.
extractorsFactory = new DefaultExtractorsFactory();
trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
trackSelector = new DefaultTrackSelector(trackSelectionFactory);
defaultBandwidthMeter = new DefaultBandwidthMeter();
dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "mediaPlayerSample"), defaultBandwidthMeter);
mediaSource = new ExtractorMediaSource(Uri.parse("https://sr11.inmystream.it/proxy/radiocircuito29?mp=/stream"), dataSourceFactory, extractorsFactory, null, null);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
player.addMetadataOutput();

There are lots of dependencies in this area, it's not just a case of sending values, you are going to need to handle notifications and media sessions.
For that, you are going to need some additional Exoplayer extensions. Specifically: MediaSessionCompat, MediaSessionConnector and connect them up to to your Exoplayer and NotificationManager.
mMediaSession = new MediaSessionCompat( this, Constants.PLAYBACK_CHANNEL_ID );
mPlayerNotificationManager.setMediaSessionToken( mMediaSession.getSessionToken() );
mMediaSession.setActive( true );
mMediaSessionConnector = new MediaSessionConnector( mMediaSession );
mMediaSessionConnector.setPlayer( mPlayer );
Once you have these, you also need to implement a DescriptionAdapter class
public class MyDescriptionAdater implements PlayerNotificationManager.MediaDescriptionAdapter
This will create the interface to populate with your static metadata. You then need to wire this up to you PlayerNotificationManager using setMediaDescriptionAdapter

Related

How to I program a web-browser to perform a series of actions?

EDIT: I'm not looking for Facebook APIs! I'm simply using Facebook as an example. I intend to get my browser to perform actions on different websites that likely have no APIs.
Let's say I wish to create a program that will log into Facebook, lookup my friends list, visit each one of their profiles, extract the date + text of each post and write this to a file.
I have an idea how the algorithm should work. But I have absolutely no clue how to interface my code with the browser itself.
Now I'm a Java programmer, so I would very much imagine the pesudo code in Java would be to create a Browser Object then convert the current page's contents to HTML code so that the data can be parsed. I provided an example code below of what I think it ought to look like.
However is this the right way that I should be doing it? If it is, then where can I find a web browser object? Are there any parsers I can use to 'read' the content? How do I get it to execute javascript such as clicking on a 'Like' button?
Or are there other ways to do it? Is there a GUI version and then I can simply command the program to go to X/Y pixel position and click on something. Or is there a way to write the code directly inside my FireFox and run it from there?
I really have no clue how to go about doing this. Any help would be greatly appreciated! Thanks!
Browser browser = new Browser();
browser.goToUrl("http://facebook.com");
//Retrieve page in HTML format to parse
HtmlPage facebookCom = browser.toHtml();
//Set username & password
TextField username = facebookCom.getTextField("username");
TextField password = facebookCom.getTextField("password");
username.setText("user123");
password.setText("password123");
facebookCom.updateTextField("username", username);
facebookCom.updateTextField("password", password);
//Update HTML contents
browser.setHtml(facebookCom);
// Click the login button and wait for it to load
browser.getButton("login").click();
while (browser.isNotLoaded()) {
continue;
}
// Click the friends button and wait for it to load
browser.getButton("friends").click();
while (browser.isNotLoaded()) {
continue;
}
//Convert the current page (Friends List) into HTML code to parse
HtmlPage facebookFriends = browser.toHtml();
//Retrieve the data for each friend
ArrayList<XMLElement> friendList = facebookFriends.getXmlElementToArray("friend");
for (XMLElement friend : friendList) {
String id = friend.getId();
//Visit the friend's page
browser.goToUrl("http://facebook.com/" + id);
while (browser.isNotLoaded()) {
continue;
}
//Retrieve the data for each post
HtmlPage friendProfile = browser.toHtml();
ArrayList<XMLElement> friendPosts = friendProfile.getXmlElementToArray("post");
BufferedWriter writer = new BufferedWriter(new File("C:/Desktop/facebook/"+id));
//Write the date+text of every post to a text file
for (XMLElement post : friendPosts) {
String date = post.get("date");
String text = post.get("text");
String content = date + "\n" + text;
writer.append(content);
}
}
I think you are thinking about this the wrong way. You wouldn't really want to write a program to scrap the screen via the browser. It looks like you could take advantage of facebooks rest api and query for the data you are looking for. A link to get a users posts via rest api:
https://developers.facebook.com/docs/graph-api/reference/v2.6/user/feed
You could get their users id's from this endpoint:
https://developers.facebook.com/docs/graph-api/reference/friend-list/
Then plug the user ids into the first rest endpoint that was linked. Once you get your data coming back correctly via the rest api its fairly trivial to write that data out to a file.

Get list of playlists in Xamarin.iOS

I am having difficulty in obtaining a collection of playlists for the iPhone with Xamarin.iOS. I want to populate a list of my custom objects with the playlist descriptions. I found a page in Apple documentation on how to do it in Obj-C. However, whatever I do in Xamarin I either get invalid cast exceptions or some other error.
Getting the playlists into a collection is OK. However, it is getting the name of the playlist after that where the problem lies.
private List<Playlist> GetPlaylists()
{
MPMediaQuery mq = MPMediaQuery.playlistsQuery;
// At this point mq.Collections has a reference to the playlists. However I have no way of getting the Name/Description of the playlist.
// Thats why I was attempting to use MPMediaPlaylist
// MPMediaPlaylist[] mp1 = mq.Collections as MPMediaPlaylist[]; - doesn't work - results in mp1 being null
List<Playlist> playlists = (from p in mq.Collections
select new Playlist () { PlaylistDescription = ((MPMediaPlaylist)p).ValueForProperty("MPMediaPlaylistPropertyName").ToString()}
).ToList();
return playlists;
}
Another variation I had was as follows (but again received an invalid cast exception in the iteration of the forearch i.e. MediaPlaylist in mp1):
MPMediaQuery mq = MPMediaQuery.playlistsQuery;
Array mp1 = mq.Collections as Array;
List<Playlist> playlists = new List<Playlist> ();
foreach (MPMediaPlaylist playlist in mp1) {
playlists.Add (new Playlist () { PlaylistDescription = playlist.ValueForProperty ("MPMediaPlaylistPropertyName").ToString() });
}
As I have commented i the code, I can get a handle on the playlists through the collections property on the query. However, I cannot get the Name/Title/Description of the playlist. That is why I was attempting to use the MPMediaPlaylist casting.
In the immediate window and watch window I tried to cast (MPMediaPlaylist)mq.collections[0] but again got an invalid cast exception.
I came across the following documentation in apple documentation for Obj-C but I have been unsuccessful in reproducing it as you can see above. I'd be very grateful if someone could cast an eye over what I have above and also this Objective-C link and advise.
Many thanks,
Tomás
I am just going to put this here.... if someone runs in to this problem in the future!
So to get list of playlists you should do the following:
MPMediaQuery playlistQuery = MPMediaQuery.PlaylistsQuery;
MPMediaItemCollection[] playlistCollection = playlistQuery.Collections;
foreach(MPMediaItemCollection collection in playlistCollection){
NSString key = MPMediaPlaylistProperty.Name;
string name = collection.ValueForKey(key).ToString();
//Do whatever you need with the info
}

Spotify API: Create Radio Button from Temporary Playlist Not supported?

I'm building an app that is generating a temporary playlist of tracks. I am then attempting to create a "Start Radio" button for that temporary playlist.
The button is generated, but when I click it, the screen changes to radio, but doesn't play nor does it load any radio station.
My guess is that this is not supported, because if I create a regular playlist and do it, it does play the radio...
But I cannot find any information in the API that confirms or deny my guess.
Does any one know for certain if this is not supported?
I would really rather do this from a temp playlist than have to maintain a real one...
You are right. The Start Radio Button doesn't support temporary playlists. And, unfortunately, the documentation doesn't mention this.
It seems that the track data attached to the temporary playlist can't be passed to the Radio app, so the Radio app loads with no context information.
The only way to achieve this is, as you said, creating a persistent playlist and create a radio button for that. In order to not create a new playlist every time, you can also try to find the playlist you created previously in the user's library.
See this code snippet:
require(['$api/models', '$api/library#Library', '$views/buttons#StartRadioButton'],
function(models, Library, StartRadioButton) {
// create a temporary playlist with some tracks
var playlistName = 'Some name';
models.Playlist.create(playlistName).done(function(playlist) {
playlist.load('tracks').done(function(loadedPlaylist) {
var track1 = models.Track.fromURI('spotify:track:5EB60KIbYgL8nWrHoYbfv4');
var track2 = models.Track.fromURI('spotify:track:7GPuYTiBA5BloBnFaQBjbw');
loadedPlaylist.tracks.add(track1);
loadedPlaylist.tracks.add(track2);
// now we can add a button to start a radio base on the newly
// created playlist
var button = StartRadioButton.forPlaylist(loadedPlaylist);
document.body.appendChild(button.node);
// bonus: we can also search for the playlist in the user's library
// so we don't have to create a new one all the time.
// this will work as long as we can find the playlist we created by name
// (i.e. it hasn't been renamed).
var currentLibrary = Library.forCurrentUser();
console.log(currentLibrary);
currentLibrary.playlists.snapshot().done(function(p) {
for (var i = 0; i < p.length; i++) {
var playlistFromLibrary = p.get(i);
if (playlistFromLibrary && playlistFromLibrary.name == playlistName) {
var button = StartRadioButton.forPlaylist(playlistFromLibrary);
document.body.appendChild(button.node);
}
}
});
});
});
});

Post an activity entry to all and to me

I try to post an activity entry with the ActivityService class. I want that all my followers and myself can see it.
this.
ActivityStreamService service = new ActivityStreamService();
service.postEntry("#me", "#all", "", jsonObject, header);
I saw my entry but not my follower
With this.
ActivityStreamService service = new ActivityStreamService();
service.postEntry("#public", "#all", "", jsonObject, header);
My follower saw the entry, but I do not see this.
Have anybody an idea which one is the correct combination?
There are a couple of ways...
1 - You can use the Distribution method
http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.5+API+Documentation#action=openDocument&res_title=Distributing_events_ic45&content=pdcontent
openSocial : {
"deliverTo":[
{"objectType":"person",
"id":"tag:example.org,2011:jane"}
]
}
*You will need a special j2ee role in order to distribute this content (trustedApplication Role in WidgetContainer Application)
2 - You can use the ublog
http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.5+API+Documentation#action=openDocument&res_title=Posting_microblog_entries_ic45&content=pdcontent
POST to my board: /ublog/#me/#all
{ "content": "A new test post" }
3 -
Otherwise, you need to do multiple posts
This means than the event would have to be sent separately to each user that is to receive the event. In order to ensure that this can be done more efficiently, an extension to the the Open Social spec allows for a few means of distribution in the data model
I hope this helps.
As well as the openSocial JSON object, you could use to JSON object
For example this JSON snippet:
"to":[
{"objectType":"person", "id":"#me"}.
{"objectType":"person", "id":"#public"}
{"objectType":"community", "id":"xxx-xx-xxx0x0x0x0x0x"}
]
...can be produced by updating your jsonObject like so:
// #me
JsonJavaObject meJson = new JsonJavaObject();
meJson.put("objectType","person");
meJson.put("id","#me");
// #public
JsonJavaObject publicJson = new JsonJavaObject();
publicJson.put("objectType","person");
publicJson.put("id","#public");
// Community
JsonJavaObject communityJson = new JsonJavaObject();
communityJson.put("objectType","community");
communityJson.put("id","xxx-xx-xxx0x0x0x0x0x");
// Shove them all in a list
List<JsonJavaObject> toJson = new ArrayList<JsonJavaObject>();
toJson.add(meJson);
toJson.add(publicJson);
toJson.add(communityJson);
// add to: [...] to the root JsonJavaObject
jsonObject.put("to", toJson ) ;
Also: Here's a video on adding a user to the trustedExternalApplication role.

How to get direct show fillter?

i am recording video from webcam using DirectshowLib2005.dll in C#.net..i have this code to startVideoRecoding as below..
try
{
IBaseFilter capFilter = null;
IBaseFilter asfWriter = null;
IFileSinkFilter pTmpSink = null;
ICaptureGraphBuilder2 captureGraph = null;
GetVideoDevice();
if (availableVideoInputDevices.Count > 0)
{
//
//init capture graph
//
graphBuilder = (IFilterGraph2)new FilterGraph();
captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
//
//sets filter object from graph
//
captureGraph.SetFiltergraph(graphBuilder);
//
//which device will use graph setting
//
graphBuilder.AddSourceFilterForMoniker(AvailableVideoInputDevices.First().Mon, null, AvailableVideoInputDevices.First().Name, out capFilter);
captureDeviceName = AvailableVideoInputDevices.First().Name;
//
//check saving path is exsist or not;if not then create
//
if (!Directory.Exists(ConstantHelper.RootDirectoryName + "\\Assets\\Video\\"))
{
Directory.CreateDirectory(ConstantHelper.RootDirectoryName + "\\Assets\\Video\\");
}
#region WMV
//
//sets output file name,and file type
//
captureGraph.SetOutputFileName(MediaSubType.Asf, ConstantHelper.RootDirectoryName + "\\Assets\\Video\\" + videoFilename + ".wmv", out asfWriter, out pTmpSink);
//
//configure which video setting is used by graph
//
IConfigAsfWriter lConfig = asfWriter as IConfigAsfWriter;
Guid asfFilter = new Guid("8C45B4C7-4AEB-4f78-A5EC-88420B9DADEF");
lConfig.ConfigureFilterUsingProfileGuid(asfFilter);
#endregion
//
//render the stram to output file using graph setting
//
captureGraph.RenderStream(null, null, capFilter, null, asfWriter);
m_mediaCtrl = graphBuilder as IMediaControl;
m_mediaCtrl.Run();
isVideoRecordingStarted = true;
VideoStarted(m_mediaCtrl, null);
}
else
{
isVideoRecordingStarted = false;
}
}
catch (Exception Ex)
{
ErrorLogging.WriteErrorLog(Ex);
}
if you observe this lines of code
//
//configure which video setting is used by graph
//
IConfigAsfWriter lConfig = asfWriter as IConfigAsfWriter;
Guid asfFilter = new Guid("8C45B4C7-4AEB-4f78-A5EC-88420B9DADEF");
lConfig.ConfigureFilterUsingProfileGuid(asfFilter);
it will apply video setting which is described on that GUID i got this GUID from file located at "C:\windows\WMSysPr9.prx"..
so my question is how create my own video setting with format,resolutions and all?
How to Record video using webcam in black and white mode or in grayscale?
so my question is how create my own video setting with format,resolutions and all?
GUID based profiles are deprecated, though you can still use them. You can build custom profile in code using WMCreateProfileManager and friends (you start with empty profile and add video and/or audio streams at your discretion). This is C++ API, and I suppose that WindowsMedia.NET, a sister project to DirectShowLib you are already using, provides you interface into .NET code.
Windows SDK WMGenProfile sample both shows how to build profile manually and provides you a tool to build it interactively and save into .PRX file you can use in your application.
$(WindowsSDK)\Samples\multimedia\windowsmediaformat\wmgenprofile
How to Record video using webcam in black and white mode or in grayscale?
The camera gives you a picture, then it goes through pipeline up to recording through certain processing. Ability to make it greyscale is not something inherent.
There are two things you might want to think of. First of all, if the camera is capable of stripping color information on capture, you can leverage this. Check it out - if its settings have Saturation slider, then you just put it input minimal value position and the camera gives you greyscale.
In code, you use IAMVideoProcAmp interface for this.
Another option, including if the camera is missing mentioned capability, is to apply post processing filter or effect that converts to greyscale. There is no stock solution for this, and otherwise there are several ways to achieve the effect:
use third party filter that strips color
export from DirectShow pipeline, convert data in code using Color Control Transform DSP (available starting Win Vista) or GDI functions
use Sample Grabber in the streaming pipeline and update image bits directly

Resources