DRM Framework implementation error - java

I am developing an ebook reader as an android app. But I want the downloaded ebook files (eg. epub) to be DRM protected. I referred to the links mentioned below and tried to implement it but resulted with an error. I am at very beginning level of implementing DRM.
My Code:
DrmManagerClient drmManagerClient = new DrmManagerClient(getApplicationContext());
DrmInfoRequest drmInfoRequest = new DrmInfoRequest(0, "text/plain"); //<--- Error in this line
DrmInfo drmInfo = drmManagerClient.acquireDrmInfo(drmInfoRequest);
Log.e("sth...: ", drmInfo.getInfoType() + "");
Error:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.user.androiddrm/com.example.user.androiddrm.MainActivity}:
java.lang.IllegalArgumentException: infoType: 0,mimeType: text/plain
The basic code above is implemented based on the following documentation:
https://developer.android.com/reference/android/drm/package-summary.html
https://developer.android.com/reference/android/drm/DrmManagerClient.html#acquireDrmInfo(android.drm.DrmInfoRequest)
https://developer.android.com/reference/android/drm/DrmInfoRequest.html
https://source.android.com/devices/drm#DrmInfo
Now the Link 4 explains about drm but using MediaPlayer as example but mine is for epub files. Even though the implementation of acquireDrmInfo() is different as followed to the above 3 links.
This link specifically targets for media player Exoplayer, so not much of help.
Note: After the epub file is downloaded, the user should be able to read offline so I don't think there will be any online activity.
So how to fix above error and is there any better tutorials on using Android.Drm Framework?

Related

Play Framework: Images not accessible in production, despite trying the "route + custom action" solution

We have a web application comprising a client in Angular2 and a server in Play Framework 2.6. This application should allow users to upload their own images. Similarly to many users here, we faced the problem of not being able to access the images in public/assets in production mode, and so we tried the solutions that have been provided to those users, with no success.
We created the following route in the conf/routes file:
GET /files/*file controllers.AdminExerciseCtrl.serve(file)
leading to the following custom action:
public Result serve(String file) {
Boolean DEVELOPMENT = Boolean.parseBoolean(ConfigFactory.load().getString("development"));
String path;
if(DEVELOPMENT) path = "public/";
else path = ConfigFactory.load().getString("root/");
return ok(new java.io.File(path + file));
}
i.e., we are saving the uploaded images to root/files/images.
We tried two way of accessing this route:
Using #routes throws an error because of the # character
Using the route in the src field (where resource.resourcePath is a variable holding the path to the image file, e.g., images/pic.jpg), the route simply isn't found (404).
<img *ngIf="resource" class="thumbnail" [src]="'/files/' + resource.resourcePath">
We are starting to despair since this project is considerably large and uploading images is a core feature. Any ideas of what we could be missing? Anything we should be doing in the client regarding the routes?
Thanks in advance.

Wicket: rendering HTML5 audio from plain string

I'd like to render HTML5 audio using Apache Wicket.
I am trying to render it from plain string. I know it's probably not the best way to do this so first I'd like to ask: is it even possible without getting errors?
Here's what I'm doing:
JAVA:
String html5AudioStr = "<audio controls><source src=\"test.mp3\" type=\"audio/mpeg\">Your browser does not support the audio element.</audio>";
add(new Label("html5Audio", html5AudioStr).setEscapeModelStrings(false));
HTML:
<span wicket:id="html5Audio"></span>
By doing this, I can see the audio player and the <audio> tag is rendered correctly. But I'm getting this error:
java.lang.ClassNotFoundException: test.mp3
And the file has this URL:
http://localhost:8080/wicket/bookmarkable/test.mp3
instead of:
http://localhost:8080/test.mp3
Is there anything I could do to fix it?
You use relative path for source. That's why browser is trying resolve absolute path relative to your page (seems it's located in /wicket/bookmarkable/).
If you are going to use / context you can simply add "/" before "test.mp3" - it should be "/test.mp3".
But if you are going to mount your application to other place rather then root context "/", I recommend to take a look to 'ContextRelativeResource'.
As of Wicket 7 media tags (audio, video, track, source) are now part of the core API.
Documentation:
Wicket User Guide 7.x - 16.3 Package resources
"Media tags - resource references with content range support"
Javadoc:
https://ci.apache.org/projects/wicket/apidocs/7.x/index.html - Packages:
org.apache.wicket.markup.html.media
org.apache.wicket.markup.html.media.audio
org.apache.wicket.markup.html.media.video
There are also some additional implementations in the "html5" module of WicketStuff about Subtitles and WebRTC.
https://github.com/wicketstuff/core/wiki/Html5

Problems connecting to YouTube Data API v3 using Java client library - sample code outdated?

This is a very basic beginner question, but I checked the main API site (https://developers.google.com/youtube/v3/) pretty thoroughly and messed around for quite a frustrating while with the sample code, used Google to find other working examples and I came up with nothing so I decided to ask here.
My aim is to write a simple Java program that connects to a YouTube account and retrieves the names and contents of the user's playlists, then possibly saves them to a text file or w/e.
I didn't find much on the site to explain exactly what steps are involved in properly connecting to a YouTube account through Java, so I tried running some sample code. If I take this for example:
https://developers.google.com/youtube/v3/code_samples/java#retrieve_my_uploads
And paste it into Eclipse, it tells me the following:
The type "FileCredentialStore" is deprecated.
At the following method:
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load( JSON_FACTORY, MyUploads.class.getResourceAsStream("/client_secrets.json"));
It tells me:
"The method load(JsonFactory, Reader) in the type GoogleClientSecrets is not applicable for the arguments (JsonFactory, InputStream)"
A bit of Googling led me somewhere that suggested the method used in the example which uses an InputStream was deprecated and later removed in 1.16 I believe.
Later the following error occurs:
channelRequest.setMine("true");
Where the String "true", should be the boolean value true. Again I'm assuming a previous version of that method was deprecated.
I've tried messing around with it, trying to piece things together from Google but it hasn't worked at all. The code seems to be outdated and not to work with the latest version of the API, and most code I can find online seems old too. I don't know enough about what I'm doing and I can't find any documentation that actually outlines what steps are required, why, and how they work.
For instance, I can't figure out what client_secrets.json is for and how it's supposed to be set up, beyond it being a part of authentication. If the API site explained it fully, I couldn't find where.
Does anyone know of a site with some working up-to-date sample code that performs some simple connection and data retrieval? Or a proper step-by-step guide that explains how to connect?
I would've thought something like the YouTube API would be straightforward and well-documented but I just can't get my head around it, unless I've missed something important but I'm out of ideas.
Google API says:
load method with InputStream is Deprecated. (scheduled to be removed in 1.16) Use load(JsonFactory, Reader) instead. Source
Thus convert InputStream to Reader and problem solved
private static GoogleClientSecrets loadClientSecrets(String clientSecretsLocation) {
try {
Reader reader = new InputStreamReader(BigQueryJavaGettingStarted.class.getResourceAsStream(clientSecretsLocation));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(new JacksonFactory(),
reader);
} catch (Exception e) {
System.out.println("Could not load client_secrets.json");
e.printStackTrace();
}
return clientSecrets;
}

How to set/get profile data with XMPP using Smack

I am working on a XMPP client on Android, using the Smack library. The roster/messaging/presence stuff is running very well. However, I didn't find a way to store additional profile information (userpicture, the dogs name, ...).
The only way I see from googling is using VCards. But it simply did not work. I tried the following:
VCard vCard = new VCard();
vCard.load(connection);
vCard.setEmailHome("meine_home#email.de");
vCard.setLastName("Scheller");
vCard.setField("blafasel", "asdf");
vCard.save(connection);
Then I was looking for a way to see that VCard information. It did neither show up in iChat nor in this System.out:
vCard.load(connection, user);
System.out.println(user + " has this vCard: " + vCard.toXML());
So anything went wrong, but theres no indication what it was. I tried this with the google talk server and my own copy of openfire with the same result. Btw, I am using this version of Smack: http://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/
What am I doing wrong here? What is the correct way of storing profile related information with Smack?
I have checked out the source of Smack and went through the important parts with a debugger, as well as using the Smack Debug Window. The problem is inside the VCard implementation of the Smack API. Saving a VCard does work as described, however the loading is broken.
parseIQ(XmlPullParser parser) is part of the PacketReader.java class and handles different types of packages. It only handles tags with the following namespaces:
"jabber:iq:auth",
"jabber:iq:roster",
"jabber:iq:register",
"urn:ietf:params:xml:ns:xmpp-bind"
It also looks if there is any registered IQProvider in the ProviderManager. And this is the root of my problem. There is no IQProvider for VCards registered. So whatever information is inside of the vCard tag simply gets dropped.
It is not too hard to register this IQProvider though:
ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new VCardProvider());
This solved my little example above for saving my own vCard and downloading it again. I am still having trouble with downloading other users vcards... Gonna have a closer look into this and maybe open up another thread for that issue.
You can use the following code to get info.
VCard card = new VCard();
card.load(connection, "user#fqdn");
System.out.println("Voice: "+card.getPhoneHome("VOICE"));
Try setting a vCard for that user with another client first, and see how that changes your results. In order to diagnose further, you'll need to turn on protocol debugging in Smack (use "-Dsmack.debugEnabled=true" on a desktop machine), and post the relevant bits here.

Problem with ImageTools plugin in Grails

i have a grails project with an Image Domain Class and Controller.
I just installed the grails ImageTools 1.0.4 Plugin and i would like to generate thumbnails for images wich will be uploaded.
My Image-Domain-Class:
class Image {
byte[] data
//String name
byte[] thumbnail
static constraints = {
//name()
data()
}
}
The "safe"-action in my Controller:
def save = {
def imageInstance = new Image(params)
def imageTool = new ImageTool()
imageTool.load(imageInstance.data)
imageTool.thumbnail(320)
imageInstance.thumbnail = imageTool.getBytes("JPEG") //Here is my problem!
if(!imageInstance.hasErrors() && imageInstance.save()) {
flash.message = "Image ${imageInstance.id} created"
redirect(action:show,id:imageInstance.id)
}
else {
render(view:'create',model:[imageInstance:imageInstance])
}
}
When I start my Grails-application and uploading an image I'm getting the following error-message:
Error 200: groovy.lang.MissingMethodException: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Servlet: grails
URI: /grailsproject/grails/image/save.dispatch
Exception Message: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Caused by: groovy.lang.MissingMethodException: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Class: GrailsAuthenticationProcessingFilter
At Line: [57]
It says that the Method getBytes() is missing but the method is still available. My IDE intelliJ also recognizes no errors.
So what can I do? Could someone help me please?
Sorry for my bad english. If you are german, please look at http://support-network.info/board/problem-mit-imagetools-getbytes-t3008.html .
I use Grails 1.0.4.
I could fix this error message. I just copied the getBytes() method from the git Repository of Ricardo (the plugin developer) and replaced the old one with the new one. Now everything works! I don't know where the bug was but i'm happy that i solved it.
Thank you both very much!
Looks like that method is a fairly new addition to the class (3/6/2009). If you have verified that that method is in the ./plugins/imagetools/src/groovy/ImageTool.groovy file I'd recommend running:
grails clean
If you had been using this plugin prior it might be a cache problem.
The reply that you received from John sounds about right - if you have installed the new plugin and can see the code, but keep getting this error only outside IntelliJ, you should try cleaning your grails cache - it's very possible that an older copy of the plugin is precompiled on the cache.
Are you using Grails 1.1? I haven't yet tested it with the latest grails, but I understand it keeps the plugins not under the project but in a separate directory. Do let me know and I'll try it out.
I don't know what the plugin is really giving you over using JAI directly, IMHO it isn't doing much.
I use ImageMagick out of process for my image conversion and the results are superior to what can be done with JAI from what I have seen. Of course if your doing as much traffic as Amazon running out of process is not an option, however if you need to get to revenue as quickly as possible then you might want to consider what I've done.
I use apache-commons-exec to have a nice interface around handling opening an external process and reading data from std in and out. The only thing I'm using JAI for is to read the sizes of images.
try this one http://support-network.info/board/gel%C3%B6st-problem-mit-imagetools-getbytes-t3008.html

Categories