I'm using Android Studio and i need to add ExoPlayer in my app and i need to use a specific user-agent, so i found this MagicalExoPlayer :
https://github.com/HamidrezaAmz/MagicalExoPlayer
This "version" of ExoPlayer is very easy to use and in the readme we can see it's easy to put specific header.
So i tried to put a specific user-agent like this :
HashMap<String , String> extraHeaders = new HashMap<>();
extraHeaders.put("User-Agent","My User Agent");
andExoPlayerView.setSource("STREAM_URL", extraHeaders);
But the user-agent don't change, i have the default user agent of ExoPlayer.
So how to use a specific user-agent with ExoPlayer ? (it's Better if i can use MagicalExoPlayer).
The User Agent is provided to the Exoplayer while preparing the datasource for the player. Example:
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context,"MY_USER_AGENT");
Since MagicalExoPlayer is a wrapper over Exoplayer, it has set the field to a constant. See the PublicValues.java class in the github repository. You can ask the author to expose a public setter to the field. Another way would be copy the library module to your project and change the value of User Agent in the PublicValues class. You'll need to change the build.gradle to compile the module. I would strongly advise to ask the author and not copy over the module unless it is necessary because you'll have to manually update the module afterwards.
Related
I am trying to get a specific Member object from a Guild by using the following:
event.getGuild().getMember(user)
Here, user is the User object of the user I want to get the Member object from. I have also tried using the .getMemberById, using the userID instead. However, in both cases I get a null-pointer exception.
I am sure that both my User object and userID are correct, because when adding a breakpoint it does show these, but it doesn't retrieve the Member, this stays null. Am I approaching this wrong?
I have also tried putting the following in my main file where I start the bot:
JDABuilder builder = JDABuilder.createDefault(BOT_TOKEN);
builder.enableIntents(GatewayIntent.GUILD_MEMBERS);
On the Discord developer portal I have enabled both the 'Privileged Gateway Intents' options.
The documentation of Guild#getMember tells you to see also Guild#retrieveMember which can be used to load members that are not cached.
If you have an event with a getMember() or retrieveMember() method, that should be used instead. Otherwise you can do this:
guild.retrieveMember(user).queue(member -> {
... use member here
});
Other alternatives are outlined in the JDA wiki here: Gateway Intents and Member Cache Policy
Most of these retrieval methods DO NOT require the privileged intent GUILD_MEMBERS. It is only required if you want to interact with the entire member list of a server, through methods like loadMembers or findMembers for example.
I'm looking to create an Aion account/address when a user creates a new account on a website. The only way I have found is via the web3 API. Is there a way to do it on the backend with using the Java plugins?
Or is there a third party API that can facilitate this?
Or what is the best practice for creating user accounts that are relatively seamless and the user does not need to know much about the interactions?
I have checked the https://docs.aion.network page but there does not seem to be any relevant information.
Welcome to StackOverflow!
There is currently no way to programmatically create an account from within a Java contract. There is the Blockchain.create() function, but that is specifically for creating Java contracts.
There is this repo that you can use to create a private and public key using Java.
If you're creating a frontend however, you should use something like Web3.js to create an account object:
async function createAccount() {
const account = web3.eth.accounts.create(web3.utils.randomHex(32));
return account;
}
Then you could have a button in your HTML that calls createAccount().
I have a class which is used to generate endpoints to the save in Google Cloud Datastore. I populate objects of this class on the application side and then call the generated API to store them (I'm using Objectify)
I've recently added a new field of type List<String> including a method to add strings to the list. However on the application said I can only see the old version of the class (which is imported from backend.MyApi.model.MyClass)
The culprit according to Android Studio is in backend/build/libs/backend-android-endpoints.jar which has a MyClass.class object
I've tried deleting the build files in the backend module, cleaning and rebuilding but it still uses the old version
How do I force the class to be rebuilt using the new source to include the new fields/methods?
So I think I've found the solution.
Any class defined as an entity by Objectify shows up in API.model but only with getters and setters for its defined fields. Therefore my add method isn't part of it
Therefore to include the functionality of add() instead on the application side I write
List<String> classList = classInstance.getClassList();
String stringToAdd = "Blah";
if (!classList.contains(stringToAdd))
{
classList.add(stringToAdd);
classInstance.setClassList(classList)
}
Assume that we have an application that use Realm and one of it's libraries the app depends use Realm also (for it's own use).
How the Realm deals with the situation that the app and the library set (both) the Realm defaultConfiguration?
The defaultConfiguration is static variable and it's value is the same for the app and the library.
In addition, if the user choose database name that he never used, if the library have also the same database name, how the Realm deals with that (they both, the app and the library have the same Context.getLibFiles)?
If the library and app both are both using defaultConfiguration, it depends on the timing of calling getDefaultConfiguration(). You can see from the source code:
public static void setDefaultConfiguration(RealmConfiguration configuration) {
if (configuration == null) {
throw new IllegalArgumentException("A non-null RealmConfiguration must be provided");
}
defaultConfiguration = configuration;
}
It doesn't have any protection and checking when set it since it is designed to be called before user calling any getDefaultRealm() (or switching the default Realm).
IMO, lib should not set the default configuration at all. The default configuration should be controlled by the app itself.
Similar situation for the same Realm name problems for lib and app. Maybe you should consider to give the lib user a chance to set the Realm name or add domains to the lib's Realm to avoid collisions?
I have an app that shows video streaming using video views.
Since the video formats I want to show are not supported by Android Versions <2.0 I am using the vitamio library to show the videos on older devices.
However Vitamio is way slower than Android video view libraries and i don't want to use it on all devices; i just want to use it on older ones.
However the names of the libraries and the methods are the same:
i.e.
import android.media.MediaController;
import io.vov.vitamio.MediaController;
In the class I only import the android Media controller and i access the vitamio one like this:
io.vov.vitamio.widget.MediaController mediacontroller = new io.vov.vitamio.widget.MediaController(parentActivity);
which works fine until I want to access one of the methods of the vitamio library. For example:
videoView.io.vov.vitamio.widget.VideoView.setVideoURI(video);
This does not work as the correct use is:
videoView.setVideoURI(video);
If I do that then the Android media player is accessed and the code isn't correct.
How can I access a method with the same name in the same class. I want to be able to use both methods based on the device of the user.
Thanks in advance.
videoView.io.vov.vitamio.widget.VideoView.setVideoURI(video);
By doing that you are trying to call the method in a static way.
You should be declaring your videoView variable as an instance of videoView.io.vov.vitamio.widget.VideoView and then call the appropriate method :
// declaration of variable as an instance of the correct class
videoView.io.vov.vitamio.widget.VideoView videoView;
// now, use the method
videoView.setVideoURI(video);
Check your class VideoView is from type "videoView.io.vov.vitamio.widget.VideoView" and not "android.widget.VideoView".
You don't need videoView.io.vov.vitamio.widget.VideoView.setVideoURI(video), it should be videoView.setVideoURI(video) where videoView is of type io.vov.vitamio.widget.VideoView.
If it's an Object, you can cast explicitly: ((io.vov.vitamio.widget.VideoView)myObject).setVideoURI(video).