I have a google-tv application that should play some sort of media (hls)
i am trying to control the volume but thought it is not working
i am using the following code in the oncreate:
setVolumeControlStream(AudioManager.STREAM_MUSIC);
and then when trying to modify the volume: audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volumedown, AudioManager.FLAG_SHOW_UI);
where volumedown is the desired new volumne.
the volumne control is appearing on the screen and moving forward and backward but the volume is not functional.
can anyone tell me what is wrong with that and how could i solve this issue?
Try this, works for me
#Override
public void VolumeUp()
{
AudioManager audioManager = (AudioManager) getSystemService(getApplicationContext().AUDIO_SERVICE);
int actualVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, actualVolume + 1, AudioManager.FLAG_SHOW_UI);
}
// Decrease volume
#Override
public void VolumeDown()
{
AudioManager audioManager = (AudioManager) getSystemService(getApplicationContext().AUDIO_SERVICE);
int actualVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, actualVolume - 1, AudioManager.FLAG_SHOW_UI);
}
Related
Where should I put this chunk of code in order the listener function works every time I enter the app from the deep link?
Now in my unity mobile app I have this code in the initial load, however it does not work well.
The first case of entering the app from the deep link is not being handled. Only after initial load when I click the deep link my listener function works (as the listener is already set).
Is there any solution to this issue?
void Start()
{
DynamicLinks.DynamicLinkReceived += OnDynamicLink;
}
// Display the dynamic link received by the application.
void OnDynamicLink(object sender, EventArgs args)
{
var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
Debug.LogFormat("Received dynamic link {0}", dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
}
Test this, feel free to edit.
void Start()
{
StartCoroutine(WaitLoader()); //Loader
}
public void trueAwoken()
{
DynamicLinks.DynamicLinkReceived += OnDynamicLink;
}
public IEnumerator WaitLoader()
{
int i = 0;
while (i < 5) // Potential for true load state 5 (increase this 0-1000+?, it depends on your build?)
{
i++;
//Debug.Log("Waiting: " + i + "/" + Time.deltaTime);
yield return new WaitForFixedUpdate();
}
trueAwoken();
}
In my app, I have a searchbox which allows users to filter as they type. For some reason I can't get an InfinteProgress to properly display while the filtering is being executed.
Here's my code:
Pass 1
public void renderForumList(){
try{
magnify = mStateMachine.findForumSearchIcon(form);
}catch(NullPointerException ex){
System.out.println("User typed additional character in search term before previous term finished executing");
}
InfiniteProgress infi = new InfiniteProgress();
magnify.getParent().replace(magnify, infi, null);
Display.getInstance().invokeAndBlock(new Runnable() {
#Override
public void run() {
for (int i = 0;i < containerStates.length;i++){
if(containerStates[i] != listItems[i].isVisible()){
listItems[i].setHidden(!containerStates[i]);
listItems[i].setVisible(containerStates[i]);
}
}
Display.getInstance().callSerially(new Runnable() {
#Override
public void run() {
mStateMachine.findForumsListComponent(form).animateLayout(200);
mStateMachine.findContainer2(form).replace(infi, magnify, null);
}
});
}
});
}
In this version, the infinite progress shows up in the proper position, but it doesn't spin.
Pass 2
public void renderForumList(){
try{
magnify = mStateMachine.findForumSearchIcon(form);
}catch(NullPointerException ex){
System.out.println("User typed additional character in search term before previous term finished executing");
}
InfiniteProgress infi = new InfiniteProgress();
magnify.getParent().replace(magnify, infi, null);
for (int i = 0;i < containerStates.length;i++){
if(containerStates[i] != listItems[i].isVisible()){
listItems[i].setHidden(!containerStates[i]);
listItems[i].setVisible(containerStates[i]);
}
}
mStateMachine.findForumsListComponent(form).animateLayout(200);
mStateMachine.findContainer2(form).replace(infi, magnify, null);
}
}
}
In this version, the magnifier icon just flashes briefly, but the InfiniteProgress spinner is never visible.
I get the same results on the simulator and on an Android device.
How can I get the InfiniteProgress to spin while the search is taking place?
invokeAndBlock opens a new thread and thus violates the EDT as you access UI components on a separate thread.
Try using callSerially instead to postpone the following code into the next EDT cycle although I'm not sure that will help as everything is still happening on the EDT.
Alternatively I'm guessing the method isVisible takes time, so you can enclose that call alone in invokeAndBlock.
To understand invokeAndBlock check out the developer guide https://www.codenameone.com/manual/edt.html
I'm having a difficult time getting my health bar to sync through the server on Unity using RPCs. In my game, the characters have health bars over their heads that are supposed to update for the entire server. That way you can just look at another player and see their health bar. The problem is that even though I send the information through the network and it's received, the actual physical bar doesn't change in scale. The player who sends the call has their bar changed though.
Here's a screenshot of the issue: http://i.imgur.com/g2GozZv.png
When I send the RPC, It does change the other player's health value, but does nothing to the scale.
I did the following code and it doesn't work:
void Start()
{
if(!networkView.isMine)
{
enabled = false;
}
}
void Update ()
{
if(Input.GetKey(KeyCode.Alpha2))
{
Minus_Health();
}
}
public void Minus_Health()
{
health -= 10;
healthBarLength = (float)health / (float)maxHealth / 5.1f;
healthBar.scale = new Vector2(healthBarLength, healthBar.scale.y);
Update_HP(health, maxHealth, healthBar.scale);
}
public void Update_HP(int hp, int maxHP, Vector3 bar)
{
networkView.RPC("Update_Health",RPCMode.All, hp, maxHP, bar);
}
[RPC]
public void Update_Health(int value, int value2, Vector3 bar)
{
health = value;
maxHealth = value2;
healthBar.scale = new Vector2(bar.x, bar.y);
}
I've also tried this, with no luck either:
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (stream.isWriting)
{
Vector3 networkHealth = healthBar.scale;
stream.Serialize(ref networkHealth);
}
else
{
Vector3 networkHealth = Vector3.zero;
stream.Serialize(ref networkHealth);
healthBar.scale = networkHealth;
}
}
I found the problem. The code itself was working great (and you're right pek, that bar parameter was just tedious).
The problem was actually with the ex2D plugin I was using for the health bar. On each exSprite there is a camera view, set to the user's main camera. Because it was set to my camera on player instantiate, it was only seeing my bar through my camera, thus not updating the other bar via client / server side. By clicking on the texture and setting the ex2D exSprite's Camera to None, I can now see both bars being updated / scaled properly.
In hopes that this can help anyone looking for how to do health bars over a network, here is the final code I'm using:
using UnityEngine;
using System.Collections;
public class PlayerStats : MonoBehaviour
{
public int health;
public int maxHealth;
public float healthBarLength = 0;
public exSprite healthBar;
void Start()
{
if(!networkView.isMine)
{
enabled = false;
}
}
void Update ()
{
if(Input.GetKey(KeyCode.Alpha2))
{
Minus_Health();
Update_HP(health, maxHealth);
}
}
public void Minus_Health()
{
health -= 10;
}
public void Update_HP(int hp, int maxHP)
{
networkView.RPC("Update_Health", RPCMode.AllBuffered, hp, maxHP);
}
[RPC]
public void Update_Health(int value, int value2)
{
health = value;
maxHealth = value2;
healthBarLength = (float)value / (float)value2 / 5.1f;
healthBar.scale = new Vector2(healthBarLength, healthBar.scale.y);
}
}
Also, a small tip for those who get errors when setting the exSprite Camera to None; You need to update your ex2D plugin.
Thanks for the help pek and I hope this can help someone! :)
If all the parameters in Update Health are correct, then there might be something else that is affecting the scale.
Also, if value and value2 are sent correctly, then there is no need for the bar parameter:
[RPC]
public void Update_Health(int value, int value2)
{
health = value;
maxHealth = value2;
healthBarLength = (float)health / (float)maxHealth / 5.1f;
healthBar.scale = new Vector2(healthBarLength, healthBar.scale.y);
}
I made gridview with Android-Universal-Image-Loader
and, when I select a picture, it's goes on the imageview.
when I select it first, it works fine. but the second one is crashed. (out of memory)
I load over 1M size image (originally took by default camera)
here is code to initialize
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.memoryCacheExtraOptions(480, 800) // default = device screen dimensions
.discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75)
.taskExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
.taskExecutorForCachedImages(AsyncTask.THREAD_POOL_EXECUTOR)
.threadPoolSize(3) // default
.denyCacheImageMultipleSizesInMemory()
.memoryCacheSize(2 * 1024 * 1024)
.discCacheSize(50 * 1024 * 1024)
.discCacheFileCount(100)
.enableLogging()
.build();
and here is get uri when it's selected
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// when clicked image
//startImagePagerActivity(position);
//URI imageUri = URI.parse("android.resource://com.kmob.camera/" + parent.getItemIdAtPosition(position));
SignUp.profilePath = Uri.parse(imageUrls[position].substring(7)); // return selected uri except prefix, "file://"
Log.v("OWL", "selected file: " + imageUrls[position].substring(7));
finish();
}
});
and here is result for activity
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
//mProfile.notifyAll();
if(profilePath.getPath().toString().length()>0){
mProfile.setImageURI(profilePath);
}
}
Thanks in advance,
According to the author suggestion mention the following two lines in displayoptions
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(Config.RGB_565) in displayioptions.
And in configuration
.memorycache(new WeakMemoryCache())
I am trying to write an application, but it is constantly crashing when using the uiimagepickercontroller. I thought that it might be because I was not disposing of the picker after each use, but it will often freeze up on first run as well. Usually I'll take a picture and it just freezes, never asking to "use" the picture.
Do you have any suggestions? Here is my code. Has anyone gotten this to work?
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
myPicker = new UIImagePickerController();
myPicker.Delegate = new myPickerDelegate(this);
myAlbumButton.Clicked += delegate {
if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary)){
myPicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
myPicker.AllowsEditing = true;
this.PresentModalViewController (myPicker, true);
}else{
Console.WriteLine("cannot get album");
}
};
myCameraButton.Clicked += delegate {
if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
myPicker.SourceType = UIImagePickerControllerSourceType.Camera;
//myPicker.AllowsEditing = true;
this.PresentModalViewController (myPicker, true);
}else{
Console.WriteLine("cannot get camera");
}
};
}
private class myPickerDelegate : UIImagePickerControllerDelegate
{
private TestView _vc;
public myPickerDelegate ( TestView controller):base()
{
_vc = controller;
}
public override void FinishedPickingImage (UIImagePickerController myPicker, UIImage image, NSDictionary editingInfo)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
_vc.myImageView.Image = image;
myPicker.DismissModalViewControllerAnimated(true);
}
}
Try to call your event handlers code from the main thread by using BeginInvokeOnMainThread().
So my issue was very similar.
Instead of having a delegate class, I had the delegates inline for the picker.
For some reason the app froze every time after talking the image, not stopping in any breakpoint after that.
The solution that worked for me was to use this book:
http://www.scribd.com/doc/33770921/Professional-iPhone-Programming-with-MonoTouch-and-NET-C