Call a wowza server from android app? - java

I'm trying to make some app that will play the stream from wowza. That part is ok. But next i need to have some option in app, that will comunicate with wowza server. For example how to call a wowza server some method, how to call onConnect method ... How to connect from wowza from a app and stay connected until i call a onDisconnect method??? If somebody have some info i will be very grateful... Thanks in advance...
VideoView.setVideoPath("some path")
does the trick for playing...

You call call a method in a Wowza module using a HTTPProvider (http://www.wowza.com/forums/content.php?30-httpproviders). This gives you a url in your Wowza module which your app will be able to call over HTTP.
So for example you have your Wowza module running under the default of:
http://localhost:1935.
You can add a HTTPProvider to your VHost.xml, such as:
<HTTPProvider>
<BaseClass>com.mycompany.wms.module.SomeModule</BaseClass>
<RequestFilters>logout*</RequestFilters>
<AuthenticationMethod>none</AuthenticationMethod>
</HTTPProvider>
This would let you call a url such as:
http://localhost:1935/logout?id=123456789
In the Java code for your module, you need implement HTTProvider2Base from which you create a onHTTPRequest method. The variables in the query string (so in this example: ?id=123456789) can be used in the method. You can also call methods in your module from here.
An example Java class that would use this call is as follows:
package com.mycompany.wms.module;
import com.wowza.wms.http.HTTProvider2Base;
import com.wowza.wms.http.IHTTPRequest;
import com.wowza.wms.http.IHTTPResponse;
import com.wowza.wms.logging.WMSLogger;
import com.wowza.wms.logging.WMSLoggerFactory;
import com.wowza.wms.vhost.IVHost;
public class SomeModule extends HTTProvider2Base {
public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
//Get the user
String userId = req.getParameter("id");
getLogger().info("Logging out user: " + userId );
logoutUser(userId);
}
private void logoutUser(String userId){
//Do stuff here...
}
private WMSLogger getLogger(){
return WMSLoggerFactory.getLogger(SomeModule.class);
}
}
Some gotchas:
Scoping in onHTTPRequest seems to be outside of your instance so be careful of accessing properties in an instance of the module.
I had to comment out the HTTPProvider node with HTTPServerVersion in it to get my one to work. It seemed to override all other HTTPProviders in my version of Wowza.
I also had trouble with the Wowza running from the IDE not picking up calls to the url via Visual Studio. Once I put my changes into the service version, the calls worked fine.
The app I built which did this was largely based on the conversation in this article: http://www.wowza.com/forums/content.php?182-HTTPProvider-that-returns-detail-server-info

Related

ebay OAuth 2.0 library Cannot Resolve method initialize()

i wanted to write a bit for Android ebay client.
but im struggeling with the first probleme.
first i start a new Java Android Project with IntelliJ
I want to use this Library ebay-oauth-android-client
like described on Git:
Obtaining Library
This library is distributed via maven central repository. To use this
library, include the below as dependency in your project
dependencies {
compile 'com.ebay.auth:ebay-oauth-android-client:1.0.1'
}
i put this snippet in my Gradle.build and replace compile with implementation since compile is depricated.
so far so good. gradle import this library.
but the next step not working for me:
Application Setup
Before performing OAuth, the library should be initialized with details about your application from eBay developer portal. The library uses
Client ID. For details see Getting your OAuth credentials
Redirect Uri. for details see Getting your Redirect_Uri
Url encoded list of scopes. for details see Specifying OAuth scopes
Use these details in ApiSessionConfiguration.initialize() as shown below:
ApiSessionConfiguration.initialize(
apiEnvironment = ApiEnvironment.PRODUCTION,
apiConfiguration = ApiConfiguration(
<Client ID>,
<Redirect Uri>,
<space separated scopes>
)
)
So i try to call initialze:
my Code with error
But when i try that the Compiler tells me that:
cannot find symbol method initialize(<null>)
When i Jump to the Class Declaration of ApiSessionConfiguration is written that:
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package com.ebay.api.client.auth.oauth2.model
public final class ApiSessionConfiguration private constructor() {
public companion object {
private final val instance: com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration /* compiled code */
public final fun getInstance(): com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration { /* compiled code */ }
public final fun initialize(apiEnvironment: com.ebay.api.client.auth.oauth2.model.ApiEnvironment, apiConfiguration: com.ebay.api.client.auth.oauth2.model.ApiConfiguration): com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration { /* compiled code */ }
}
public final var apiConfiguration: com.ebay.api.client.auth.oauth2.model.ApiConfiguration? /* compiled code */
public final var apiEnvironment: com.ebay.api.client.auth.oauth2.model.ApiEnvironment? /* compiled code */
}
i dont really understand what im doing wrong. in the sample file on Git ApiSessionConfiguration.initalize() is called without any errors.
i already tried to Invalidate Cache, Clean Build, and start over again.
when i try to import the library from Project Structure Librarys New from Maven repo it says:
no files were downloaded...
Doesn't it can resolve initialize method with single argument?
Did you tried initialize method with two arguments?
Their sample app takes 2 arguments:
https://github.com/eBay/ebay-oauth-android-client/blob/master/sample/src/main/java/com/ebay/api/client/auth/MainActivity.kt#L37-L44
Updated:
But to access to Kotlin companion object function from java you need to call ApiSessionConfiguration.Companion.initialize method

Program AOSP Launcher3 to hide specific app

I've tried to hide app from launcher by adding and changing codes form the app source but failed every time.
Is it possible to hide a specific app from the launcher by editing Launcher3 source code? btw I'm working with AOSP build and want to integrate a 3rd party Open Source app into Settings, so that it can only be opened from Settings.
Looking through the original Launcher3 source code, you will find AppFilter file under /src/com/android/launcher3. From the file name itself, we know it’s a class to filter applications. There is a method called shouldShowApp, as its name suggest, is to consider if an application is needed to show.
Following this, AllAppsList.java uses this method in the add method. Clearly, when mAppFilter.shouldShowApp return false, it will return directly, making the applications to exclude from the application list, which will not be displayed.
Thus,
The easiest way is by simply change Line the line in AppFilter.java to be return !"com.google.android.gm".equals(app.getPackageName());, where this snippet of code will make sure that the package “com.google.android.gm” (Gmail) to be excluded from showing up in Launcher.
package com.android.launcher3;
import android.content.ComponentName;
import android.content.Context;
public class AppFilter {
public static AppFilter newInstance(Context context) {
return Utilities.getOverrideObject(AppFilter.class, context,
R.string.app_filter_class);
}
public boolean shouldShowApp(ComponentName app) {
return !"com.google.android.gm".equals(app.getPackageName());
}
}
Hope this help.

JAX-RS PostConstruct / Inject tag in simple GET request project

I have been deconstructing someone's project which retrieves a response from a 3rd party API and prints it to a Vaadin web GUI.
My version is supposed to retrieve an API response from an anime website, parse this automatically (??) into an object and then print the object attribute to my screen mainly so I can see if it bloody works.
I converted a sample XML file to XSD then used JAXB to generate a class from it (and a builder but I'm not quite sure how that is used yet) in order to store my response from the API.
I have a getservice java class that performs the get request. This worked previously when all I was doing was printing the result of the request to a string and before I tried to put it into an object.
Lastly I have a main JavaApplication4 class that was apparently necessary to create an instance of the request (I'm pretty new to OO programming but it sort of makes sense maybe).
The application runs however I now get an error message:
Exception in thread "main" java.lang.NullPointerException
at javaapplication4.getservice.fetchMovie(getservice.java:36)
at javaapplication4.JavaApplication4.main(JavaApplication4.java:17)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
This points me to the line
return target.queryParam("anime", "4658")
.request(MediaType.TEXT_HTML)
.header("Content-type", "text/html")//application_json or text_html or xml
.get(Ann.class);
I used a breakpoint and found that my client and target remain as null both here and on the above lines:
#PostConstruct
protected void init() {
client = ClientBuilder.newClient();
//target = client.target("http://www.omdbapi.com");
target = client.target("http://cdn.animenewsnetwork.com/encyclopedia/api.xml");
}
Looking back at the original guy's project, I think the problem is because I am using annotations like #PostConstruct but do not have an #Inject annotation. I tried to add an #Inject to my Main/JavaApplication4 file but it either doesn't do anything (and looks completely wrong) or it tells me its not applicable where I put it.
I would totally appreciate someone to have a quick look and see if its those annotations causing the problem... I don't understand how to use them in any context yet and it is so hard to find examples that do things in a particular way, I am just left trying to reposition bits and pieces for hours and obviously that doesn't work XD
The full code of the project, MINUS the Ann.java class (which should store the API response in the form of anime , title, name, etc etc) and the ObjectFactory.java class which was generated alongside it (and im not sure what it does yet but thats another step):
Ann.java
(getters and setters and xml stuff i think)
ObjectFactory.java
JavaApplication4.java
package javaapplication4;
import generated.Ann;
import javax.inject.Inject;
public class JavaApplication4 {
//#Inject
//getservice gt;
public static void main(String[] args) {
//#Inject
getservice gt = new getservice();
String output = gt.fetchMovie().getAnime().getName();
System.out.println(output);
}
}
getservice.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication4;
import generated.Ann;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
/**
*
* #author J
*/
#ApplicationScoped
public class getservice {
private Client client;
private WebTarget target;
#PostConstruct
protected void init() {
client = ClientBuilder.newClient();
//target = client.target("http://www.omdbapi.com");
target = client.target("http://cdn.animenewsnetwork.com/encyclopedia/api.xml");
}
// these apparently stay null when i run JavaAppliation4
// do i need an #Inject somewhere or something completely similar or different?
public Ann fetchMovie() {
//return target.queryParam("anime", "4658")
return target.queryParam("anime", "4658")
.request(MediaType.TEXT_HTML)
.header("Content-type", "text/html")//application_json or text_html or xml
.get(Ann.class);
}
}
Thankyou. Its just one of those parts where "i'm stuck so i'll keep trying" doesn't look like its going to get me very far...idk... :)
#Inject and #Postconstruct relates to "managed beans", CDI. All Java EE servers provide CDI by default. If you wish to use it with plain Java SE environment, you need a CDI implementation like Weld. See this blog entry how that can be done.

Why can't I render an object to my view in Play 2?

I think I have misunderstood something about the Play 2 framework.
In my Application Controller I fetch a Company object from the DB
and I would like to make some operations on it in my view.
companyView.scala.html:
#(company: Company)
#main("Welcome to Play 2.0") {
<h1>#{company.name}</h1>
}
Application Controller:
package controllers;
import models.Company;
import play.*;
import play.mvc.*;
import views.html.*;
public class Application extends Controller {
public static Result company(String rest) {
Company company =
Company.find.where().ilike("restfulIdentifier.identifier", rest).findUnique();
return ok(companyView.render(company));
}
}
But return ok(companyView.render(company)); results in compilation error since companyView.render wants a string.
If I look at the forms sample application:
/**
* Handle the form submission.
*/
public static Result submit() {
Form<Contact> filledForm = contactForm.bindFromRequest();
if(filledForm.hasErrors()) {
return badRequest(form.render(filledForm));
} else {
Contact created = filledForm.get();
return ok(summary.render(created));
}
}
There is no problem with rendering an object. I guess that the solution is fairly simple and
that I have missed some crucial part of the documentation. Please explain this to me!
My steps in this case would be as follows:
Change the scala template, we hve to tell the scala templates the our Company belongs to the model class: (but also change to #company.name as suggested by Jordan.
#(company: models.Company)
#main("Welcome to Play 2.0") {
<h1>#company.name</h1>
}
run command play clean
Then run play debug ~run
By executing play debug ~run you will trigger to compile the the play application on each SAVE of one of your project files.
NOTE: The Play templates are basically functions. These functions needs to be compiled and everything used in these functions needs to be declared before use. Just as in regular Java development.
The fact that the your render object wants a string could be the result of:
#(company: Company) could not be resolved to the model Company.
The last compilation had a #(company: String)
Good luck!
I don't know if this will fix your problem or not but it's worth a try. Try removing changing:
#{company.name}
to:
#company.name

How to access DLL methods in Java code using JNA?

By running System.loadLibrary("myAPI"), I verified that the DLL file "myAPI.dll" can be successfully loaded into my Eclipse Java project. Now I need to call methods specified inside this DLL file from my Java code. To do this, I added JNA to my Java project. Then I wrote the below-given code snippet that should be able to get instances of classes IProject and ProjectFactory (specified in the DLL file).
I still don't understand how to properly implement this with JNA. I checked different threads, e.g. this one, but the ones I checked don't provide an answer. Any help is highly appreciated. Thanks.
import com.sun.jna.Library;
import com.sun.jna.Native;
public class MyClass {
public interface myAPI extends Library {
//...
}
void LoadProj() {
myAPI api = (myAPI) Native.loadLibrary("myAPI",myAPI.class);
String fileName = "xxx.sp";
IProject project; // this is wrong but shows what I am trying to do
try {
project = ProjectFactory.LoadProject(fileName);
}
catch (Exception ex) {
MessageBox.Show(this, ex.Message, "Load failure");
}
}
}
Not sure what problem you are facing but as a practice your myAPI interface should declare all the methods verbatim with appropriate parameter mapping. I don't see any methods inside your interface.
Please checkout the this link as well as the link mentioned above by #Perception
If there are no Java classes or Java source hidden inside this DLL (which would be ... strange), then it will never work this way. You can't instantiate C# classes or use C# interfaces. MessageBox.Show( isn't Java either, it is Windows Forms code.

Categories

Resources