Android [SOLVED] Extension problem, won't compile, unexpected return value

W

Wraithious

Guest
Hi, I'm trying to return a value asyncronously to GM:S and I'm getting this compile error:
Code:
Z:\com.roadhammergaming.dance_club\src\main\java\com\roadhammergaming\dance_club\GMMusic.java:62: error: incompatible types: unexpected return value
                        return value;
                               ^
I can't figure out why the return value is unexpected, it's a double and the recieving async code is expecting a double so what am I doing wrong?, here's my complete java file:
package ${YYAndroidPackageName};

import android.util.Log;
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;

import android.database.Cursor;
import android.provider.MediaStore;
import android.media.MediaPlayer;
import android.media.AudioManager;
import android.media.MediaPlayer.OnCompletionListener;
import android.content.Context;
import java.util.HashMap;

import java.lang.String;
import ${YYAndroidPackageName}.R;
import com.yoyogames.runner.RunnerJNILib;


public class GMMusic {


public MediaPlayer mp = new MediaPlayer();
boolean paused = false;
boolean stopped = false;
boolean init = false;

public final Cursor cursor = RunnerJNILib.ms_context.getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.MIME_TYPE, MediaStore.Audio.Media.DURATION }, null, null,
"LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");

public int currentTrack = 0;

public void Init()
{
if (!init)
{
Log.i("GMMusic", "Init called");
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {

if (!stopped)
{
if (currentTrack < NumberOfTracks()-1)
{

currentTrack++;
UpdateTrack();
}
else
{
currentTrack = 0;
UpdateTrack();
}
double value = currentTrack;//String.valueOf(currentTrack);
Log.i("yoyo", "Song has changed");
return value; //ERROR LINE 62
}
}
});
init = true;
}
}
public void Final()
{
mp.release();
}

public void PlayMusic(double track)
{

if (paused)
{
ResumeMusic();
}
else if (stopped)
{
currentTrack = (int)track;
cursor.moveToPosition((int)track);
UpdateTrack();
}
else if (!mp.isPlaying())
{
currentTrack = (int)track;
cursor.moveToPosition((int)track);
int dataSource=cursor.getColumnIndex(MediaStore.Audio.Media.DATA);

try {
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource(cursor.getString(dataSource));
mp.prepare();
mp.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
Log.i("GMMusic", "Music already playing");
}
}

private void UpdateTrack()
{
mp.reset();
cursor.moveToPosition((int)currentTrack);
int dataSource=cursor.getColumnIndex(MediaStore.Audio.Media.DATA);

try {
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource(cursor.getString(dataSource));
mp.prepare();
mp.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void NextTrack()
{
if (mp.isPlaying())
{
if (currentTrack < NumberOfTracks()-1)
{
currentTrack++;
UpdateTrack();
}
else
{
currentTrack = 0;
UpdateTrack();
}
}


}

public void PreviousTrack()
{
if (mp.isPlaying() && currentTrack > 0)
{
currentTrack--;
UpdateTrack();
}
else
{
Log.i("GMMusic", "No previous track");
}
}

public void GotoTrack(double trackNumber)
{
//music must be playing
if (mp.isPlaying() && (trackNumber >= 0 && trackNumber < NumberOfTracks()))
{
currentTrack = (int)trackNumber;
UpdateTrack();
}
else
{
Log.i("GMMusic", "Track not found, or music not playing");
}

}

public void PauseMusic()
{
if (mp.isPlaying())
{
try {
paused = true;
mp.pause();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

public void ResumeMusic()
{
if (!mp.isPlaying())
{
try {
paused = false;
mp.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

public void StopMusic()
{
if (mp.isPlaying())
{
try {
paused = false;
stopped = true;
mp.stop();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
Log.i("GMMusic", "Music must be playing to be stopped");
}
}

public double MusicPlaying()
{
return ((mp.isPlaying()) ? 1 : 0);
}
public double MusicPaused()
{
return ((paused) ? 1 : 0);
}
public double MusicStopped()
{
return ((stopped) ? 1 : 0);
}

public String GetArtistName(double track)
{
String result = "";
if (track >= 0 && track < NumberOfTracks())
{
cursor.moveToPosition((int)track);
result = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.ARTIST));
cursor.moveToPosition((int)currentTrack);
}
else
{
Log.i("GMMusic", "Track does not exist");
}
return result;
}
public String GetSongName(double track)
{
String result = "";
if (track >= 0 && track < NumberOfTracks())
{
cursor.moveToPosition((int)track);
result = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.TITLE));
cursor.moveToPosition((int)currentTrack);
}
else
{
Log.i("GMMusic", "Track does not exist");
}
return result;
}
public String GetCurrentArtistName()
{
return cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.ARTIST));
}

public String GetCurrentSongName()
{
return cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
}

public double NumberOfTracks()
{
return cursor.getCount();
}



private static final int EVENT_OTHER_SOCIAL = 70;//LINE 286
public void ReturnAsync(double value)
{
int dsMapIndex = RunnerJNILib.jCreateDsMap(null, null, null);
RunnerJNILib.DsMapAddString( dsMapIndex, "type", "finished" );
RunnerJNILib.DsMapAddDouble( dsMapIndex, "argument0", value);
RunnerJNILib.CreateAsynEventWithDSMap(dsMapIndex, EVENT_OTHER_SOCIAL);
}

}

The error is being caused by line # 62, and coincides with the async code from line 286 - 293

Please if anyone can help me out it would be greatly appreciated thanks!
 
Last edited by a moderator:
W

Wraithious

Guest
I can give some more info, and a question, So if I comment that line of code out: line62 //return value; the game compiles and works but the extension doesn't call back to my async code in GM:S. However, the Log.i("yoyo", "Song has changed"); in line 61 does register in the runner window on my computer, so I'm wondering is there a way I can get that to return to my game? I really don't even need it to return an actual value (altho it would be nice) but as long as I can get a song change notification from the extension thats all I need to do, but really, what am I doing wrong and how can I fix it? here's a screenshot showing the runner knows what's going on in the extension: (the bottom 3 lines of text)
runner.png

Maybe this may help to clarify a little, here's my Social async avent code to catch the value that's supposed to be returned to it:

Social event in persistant object timex:
Code:
var type = async_load[? "type"];
if type == "finished"
    {
    global.thisone = real(async_load[? "argument0"]);
    if global.listOn = 1 playlist(1);
    if global.listOn = 2 playlist(2);
    if global.listOn = 3 playlist(3);
    }
And the corresponding script the async event calls if it gets a value:

script playlist:
//Play the playlist in order
if (global.trkPlayed < global.plistTracks - 1 && argument[0] = 1)
{
global.trkPlayed ++;
startingTrack = global.plist[(global.trkPlayed)];
global.thisone = startingTrack;
GotoTrack(startingTrack);
}
else
{
global.trkPlayed = 0;
startingTrack = global.plist[0];
GotoTrack(startingTrack);
}
//Play the playlist randomly
if (global.trkPlayed < global.plistTracks && argument[0] = 2)
{
canloop = 1;
while (canloop = 1)
{
ckTrack = round(random(global.plistTracks));
var c;
for (c = 0;c < global.plistTracks;c ++)
{
if (ckTrack != played[c])
{
played[ckTrack] = ckTrack;
canloop=0;
startingTrack = ckTrack;
global.thisone = startingTrack;
global.trkPlayed ++;
if (global.trkPlayed = global.plistTracks)
{
var p;
for(p = 0;p < global.plistTracks;p ++)
played[p] = 0;
global.trkPlayed = 0;
}
}
}
}
GotoTrack(startingTrack);
}
//Play all songs randomly
if (global.trkPlayed < global.tracknum - 1 && argument[0] = 3)
{
canloop = 1;
while (canloop = 1)
{
ckTrack = round(random(global.tracknum));
var c;
for (c = 0;c < (global.tracknum);c ++)
{
if (ckTrack != played[c])
{
played[ckTrack] = ckTrack;
canloop=0;
startingTrack = ckTrack;
global.thisone = startingTrack;
global.trkPlayed ++;

if (global.trkPlayed = (global.tracknum))
{
var p;
for(p = 0;p < (global.tracknum);p ++)
played[p] = 0;
global.trkPlayed = 0;
ckTrack=0;
}
}
}
}
GotoTrack(startingTrack);
}
 
Last edited by a moderator:
Top