I have a javafx program that looks a little something like this:
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.media.Media;
import java.io.File;
import java.net.URL;
public class MusicPlayer
{
MediaPlayer medplay;
public void start()
{
String songDir = new File("/Users/myusername/Desktop/song.mp3").getAbsolutePath();
Media med = new Media(new File(songDir).toURI().toString());
medplay = new MediaPlayer(med);
medplay.play();
}
public void pause()
{
medplay.pause();
}
public void resume()
{
medplay.play();
}
}
I tested various different mp3s I have all of which are from the same source. They are all 320kbs mp3s as well. When I try any song from Sum 41's album 13 Voices (if that's relevant) it won't play. Also Boston for some reason. I'm not sure why these mp3s won't play as opposed to any other songs I have in mp3. I am using the BlueJ IDE(it's for high school). Is there anyway I can debug what happens start() is called, but no music starts playing? I am open to moving this project into another IDE if anyone knows better how to debug there and it would help them help me.
Related
Im really noob at coding, I know the basics, but I want an help to code a script who can detect on which terrain I'm walking on and make different sounds. On the internet there are some tutorials but they are for 3D Games, mine is a 2D Game so it's different. Can you please help me?
I would put the footstep sound in a "wrapper" method, and in that method include arguments/values that indicate the current terrain and manner-of-movement, if they matter.
For example:
playFootstep("grass", "jumping")
or:
playFootstep("gravel", "walking")
Then, in this method, select what sound file to play based on the parameters, and play it.
How do you currently play your footsteps?
Here's my footsteps code:
using UnityEngine;
public class Footsteps : MonoBehaviour
{
[SerializeField]
private AudioClip[] clips;
private AudioSource audioSource;
private void Awake()
{
audioSource = GetComponent<AudioSource>();
}
private void Step()
{
AudioClip clip = GetRandomClip();
audioSource.PlayOneShot(clip);
}
private AudioClip GetRandomClip()
{
return clips[UnityEngine.Random.Range(0, clips.Length)];
}
}
What I am trying to do is export from Blender a .dae file of an animated object and then import this file on processing and use it there. I created a rotating cube, baked action and exported it as .dae file. the problem is when I am importing it on processing the animation doesn't work and I can see only a square.
import ch.dieseite.colladaloader.ColladaLoader;
import ch.dieseite.colladaloader.wrappers.ColladaModel;
ColladaModel model;
void setup() {
size(500,600,P3D);
background(255);
lights();
frameRate(10);
model = ColladaLoader.load("cuberot.dae", this, null);
model.scale(25);
}
void draw() {
translate(width/2,height/2);
model.draw();
}
Can someone explain how this can work?
I am newbie for cucumber framework, I have worked on selenium webdriver using testNG framework. I have to start cucumber framework, I have installed cucumber plugin to eclipse but dont know how to start writting code.
And what is the difference between cucumber and cucumber-jvm, and which is the best?
Could anyone pls help me out?
Thanks in advance.
You can find lots of info on what dependecies you should use for your project on the Cucumber main site Cucumber Documentation
Cucumber base is Ruby
Cucumber-JVM is Java
start with creating a src/test/resources
create a file named anything you want (keep it to the thing you want to test) and end it with .feature
Feature: Calculator should work accourding to standard calculator devices
Scenario: addition
Given a calculator I just turned on
When I add 4 and 5
Then the result is 9
put this in as a guide line and try to run it. it should give you a call missing steps.
create a new java file in src/test/java and call it RunCukesTest this wil later be the starter of all your features.
the output you just got from the feature in the console can be put in a .java call it something to do with the feature like CalculatorSteps.java put this in the same folder as your RunCukesTest.java
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
monochrome = false,
plugin = {"pretty","json:target/cucumber.json"} ,
features = "src/test/resources/cucumber",
tags = "~#ignore"
)
public class RunCukesTest {
}
this is the basic you need to start using Cucumber (there is a start example on github)
Now the Selenium question
you will have to initiate a WebDriver _driver;
with driver you create a new ChromeDriver or FireFoxDriver etc
some browsers need a installation ChromeDriver firefox is built in (to my best knowledge)
see the code below
ask if there is anything you don't get
import java.util.concurrent.TimeUnit;
import cucumber.api.java.en.*;
import org.eclipse.jetty.util.thread.Timeout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class NavigationSteps {
WebDriver _driver;
#Given("^i am at \"([^\"]*)\"$")
public void i_am_at_home(String arg1) throws Throwable {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
_driver = new ChromeDriver();
_driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
_driver.get(arg1);
Thread.sleep(500);
}
#When("^i click on \"([^\"]*)\"$")
public void i_click_on(String arg1) throws Throwable {
_driver.findElement(By.linkText(arg1)).click();
Thread.sleep(500);
}
#Then("^i expect the title to be \"(.*?)\"\"(.*?)\"$")
public void i_expect_the_title_to_be(String arg1, String arg2) throws Throwable {
String result = (arg1 + " | " + arg2);
Thread.sleep(200);
assertEquals("Title should be",result,_driver.getTitle());
tearDown();
}
#Then("^Header should contain \"(.*?)\"$")
public void header_should_contain(String arg1) throws Throwable {
Thread.sleep(200);
assertEquals("Title should be", arg1, _driver.findElement(By.xpath(".//*[#id='main']/div[1]/div/h1")).getText());
tearDown();
}
#After
public void tearDown() throws InterruptedException
{
_driver.quit();
}
}
EDIT - answers to the questions in nicer format
feature file calls the java file (Run via RunCukesTest or feature file)
the methods to test go into je java steps file
Feature calculator has a CalculatorSteps.java file the scenario is in the feature file the methods in the steps
No, the console outputs this as a Regex to identify the corresponding step the test u write in the method below it.
Given a calculator I just turned on
results into
#Given ("^a calculator I just turned on$")
public void iCanCallThisAnythingIWant(){
#do something
}
see answer 2
Given When Then are the logical way to read a Scenario to keep things readable it should be used in that way. If you find yourself with a long Given When or Then u can split the sentence with a "and" in between. but it doesn't matter in what way u write them.
I have a problem mocking Calendar.getInstance(). As you now this method returns a Calendar - the object I am mocking.
Right now my code looks like this:
#RunWith(PowerMockRunner.class)
#PrepareForTest(Calendar.class)
public class SurveillanceDatabaseTest {
#Test
public void testFailingDatabase() throws Exception {
mockStatic(Calendar.class);
Calendar calendar = new GregorianCalendar();
calendar.add(Calendar.HOUR, 1);
when(Calendar.getInstance()).thenReturn(calendar);
final Surveillance surveillance = new Surveillance();
surveillance.checkDatabase();
}
}
Calendar.getInstance() gets called various times in surveillance.checkDatabase() and every time it is a new object and not the expected mock of Calendar.
Can anyone see what I am doing wrong?
It seems that you need to add the target test class in the PrepareForTest tag:
#PrepareForTest({ Calendar.class, Surveillance.class })
#RunWith(PowerMockRunner.class)
#PrepareForTest({ Calendar.class, Surveillance.class })
public class SurveillanceDatabaseTest {
#Test
public void testFailingDatabase() throws Exception {
mockStatic(Calendar.class);
Calendar calendar = new GregorianCalendar();
calendar.add(Calendar.HOUR, 1);
when(Calendar.getInstance()).thenReturn(calendar);
final Surveillance surveillance = new Surveillance();
surveillance.checkDatabase();
}
}
Even Tom Tresansky's example above will need it if we move the Surveillance class to somewhere outside MockCalendarTest class.
I'm not as familiar with the when(object.call()).andReturn(response); but I'm assuming it works the same way as expect.(object.call()).andReturn(response);. If that is the case, then it looks like all you are missing a replay of the class PowerMock.replay(Calendar.class) and you are trying to do a full static mock instead of a partial static mock. This should resolve your issue.
#RunWith(PowerMockRunner.class)
#PrepareForTest(Calendar.class)
public class SurveillanceDatabaseTest {
#Test
public void testFailingDatabase() throws Exception {
Calendar calendar = new GregorianCalendar();
calendar.add(Calendar.HOUR, 1);
PowerMock.mockStaticPartial(Calendar.class, "getInstance"); //Mock Static Partial
expect(Calendar.getInstance()).andReturn(calendar);
PowerMock.replay(Calendar.class); // note the replay of the Class!
final Surveillance surveillance = new Surveillance();
surveillance.checkDatabase();
//Whatever tests you need to do here
}
}
It seems like you're doing everything right. For instance, this test below passes, proving that the Calendar returned by Calendar#getInstance() is in fact the one you set up with the static mocking.
import static org.junit.Assert.*;
import static org.powermock.api.mockito.PowerMockito.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PrepareForTest(Calendar.class)
public class MockCalendarTest {
#Test
public void testFailingDatabase() {
mockStatic(Calendar.class);
final Calendar testCalendar = new GregorianCalendar();
testCalendar.add(Calendar.HOUR, 1);
when(Calendar.getInstance()).thenReturn(testCalendar);
final Surveillance surveillance = new Surveillance();
final Calendar resultCalendar = surveillance.checkDatabase();
assertTrue(testCalendar == resultCalendar);
}
public static class Surveillance {
public Calendar checkDatabase() {
return Calendar.getInstance();
}
}
}
Perhaps post the relevant parts of the Surveillance class so we can see how it's trying to get a new Calendar and assess why it's failing.
Hi I'm completely new to android programming and use AIDE via tablet.
I'm trying to create a very basic program with a Spinner box that gives output on the selection Ive made via an TextView or System.Out.printIn. (Perhaps the next step up from Hello world - if you will)
For some reason that I cannot fathom,the compiler refuses to recognise the OnClickListener and gives the error message 'Unknown method OnClickListener in Android.Widget.Spinner'
When I have already checked this in the imports.
As a matter of interest I have changed the name of the Spinner and the error seems to dissapear, the problem then is the Spinner name. I have tried several variations on this, and have came to the conclusion that the best option for me is to create a variable just after Main Acivity, and before the layout is declared.
I have also disabled one of the overrides in order to resolve my problem
has anyone got an idea what the problem could be?
package com.BGilbert.AUC;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.View.OnClickListener;
import android.widget.Spinner.*;
import android.view.*;
public class MainActivity extends Activity {;
String Fbstring;
OnClickListener Myonclick;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
final Spinner Fbspinner=(Spinner)findViewById(R.id.Spinner);
// The problem is with this line. OnClickListener just wont be
// recognised
Fbspinner.OnClickListener(Myonclick);
}
// Override previously disabled
#Override
public void Onselect(AdapterView<?> parent,View V, int pos, long id) {
Fbstring = parent.getItemAtPosition(pos).toString();
System.out.println(Fbstring);
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
}
You can't set an onClickListener on a spinner, only on it's views which is too advanced for you at the moment. Instead, use an onItemSelectedListener.
public class MainActivity extends Activity extends Activity implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
...
...
}
You should read the documentation first http://developer.android.com/guide/topics/ui/controls/spinner.html
Also try to use standard naming conventions:
http://www.oracle.com/technetwork/java/codeconv-138413.html
http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367
Finally, you have many problems in this code, e.g.
public class MainActivity extends Activity {;
Note the semicolon at the end.
Get your code compiling first, then come back with your next question.
Good luck