AdMob - RewardVideo not giving out reward after video is finished - ios

I have AdMob installed in my sprite kit game and I'm using mediation to get reward videos for the user so that they can earn in game coins but when they watch the video it plays but doesn't give the reward. Now when I try and type out the function it doesn't show a function that gives the reward.
but when I copy and paste it xcode doesn't give me an error but it still doesn't give me the reward.
what is the problem and how can I fix it?
EDIT
I show the reward video like so:
func showRewardVideoAd() {
if rewardVideoAd.isReady {
let vc = self.scene?.view?.window?.rootViewController
rewardVideoAd.present(fromRootViewController: vc!)
rewardVideoAd = createRewardAd()
}
}

Related

Unity/Videoplayer - Game sometimes crash if I load next video

I use Video Player which attached 3D game object. This game object contain "Mesh Renderer" component too. Video Player Renderer-> this game object.
I try many method, but always crash game.
I try use in Update: Videoplayer().isplaying if false, then I load from Resources next video and play, but not working. (Unity Editor working fine, but in iPhone sometimes crash game.)
Then I try other method..
But sometimes crash too..
Okey, I think maybe loading and start playing too fast, maybe this cause the crash.
Then I try use Ienumerator waitforsecond every step, for debugging I set it 5 seconds.
I try first set video player.clip = null, maybe this is the problem.. But not..
Now the code:
void Start()
{
index = 0;
videoPlayer = gameObject.GetComponent<VideoPlayer>();
videoPlayer.loopPointReached += CheckOver;
}
IEnumerator Waitforseconds()
{
Debug.Log("Waitforseconds start");
videoPlayer.clip = null;
Debug.Log("Videoplayer clip null);
yield return new WaitForSeconds(5);
videoPlayer.clip = theVideo;
Debug.Log("Videoplayer set the video");
yield return new WaitForSeconds(5);
Debug.Log("Next play video player");
videoPlayer.Play();
Debug.Log("Play video player");
isPlaying = true;
}
void CheckOver(UnityEngine.Video.VideoPlayer vp)
{
Debug.Log("Checkover");
index += 1;
if (index >= videos.Length)
{
index = 0;
}
theVideo = videos[index];
Debug.Log("Set the video");
StartCoroutine(Waitforseconds());
}
The videos size 5-10 MB and 10-60 seconds.
The result: Unity Editor working good, I build to iOS and sometimes crash the game if I play next video (iPhone 12 Pro Max, supposedly the fastest smartphone chip, so if that doesn't work, there's a big problem..)
Debug:
I get last Debug.log before the game crash:
"Videoplayer clip null"
So I think the game crash here: videoPlayer.clip = theVideo;
But only iOS! Unity editor working good.
Xcode error:
I try find solution in google, but I can't find..
Maybe memory error? should I somehow delete the previous video from memory?
Or how can I solve this problem? Please help me.
Thank you very much!
EDIT: I see the problem is Audio. (Audio Output mode: Audio Source, this component attached to same gameobject. So same game object contain audio source and video player.) If I set Audio Output mode to "none", then game not crash, workin good. So the problem when "PrepareAudioTap". How can I solve this problem?
Solved!
I change Video Player component "Audio Output mode": Audio Source to Direct.
Then not crash game.
But I would like to use Audio Source, because I need 3D Sound. (not important, I'm glad it works, but if you have idea how to work with 3D sound, I would be glad.)
Thanks!

Inaccurate face detection using ML Kit Face detection, doesn't work with selfies

I am creating a iOS app that uses the Firebase ML Kit Face Detection and I am trying to allow users to take a photo from their camera and check if there was a face in it. So I have followed the documentation and some youtube videos but it seems that it just doesn't work properly/accurately for me. I did some testing using a photo library not just pictures that I take, and what I found is it works well when I use selfies from google, but when I take my own selfies it never seems to work. I noticed when I take a selfie on my camera it does like a "mirror" kind of thing where it flips it, but I even took a picture of my friend using the front facing camera and it still didn't work. So I am not sure if I implemented this wrong, or what is going on. I have attached some of the relevant code to show how it was implemented. Thanks to anyone who takes the time to help out, I am a novice at iOS development so hopefully this isn't a waste of your time.
func photoVerification(){
let options = VisionFaceDetectorOptions()
let vision = Vision.vision()
let faceDetector = vision.faceDetector(options: options)
let image = VisionImage(image: image_one.image!)
faceDetector.process(image) { (faces, error) in
guard error == nil, let faces = faces, !faces.isEmpty else{
//No face detected provide error on image
print("No face detected!")
self.markImage(isVerified: false)
return
}
//Face Has been detected Offer Verified Tag to user
print("Face detected!")
self.markImage(isVerified: true)
}
}

Play IOS Music Library Content Using AVFoundation

I'm attempting to write an IOS app that will play my iPhone music library content, showing artwork, and "announcing" title, artist, etc.
I have it working nicely using Apple's Media Player framework. I can display Playlist names and queue the songs in a selected Playlist.
I use the "MPMusicPlayerControllerNowPlayingItemDidChange" observer notification to pause playback, retrieve metadata, and do the announcements via AVSpeechSynthesizer.
I was a happy camper until I ran into the dreaded "Media Player framwork doesn't respond to observer notifications in background" issue.
So, I started looking at the AVFoundation Framework. I found a sample that plays local song files via URLs in the background and.
I'm failing miserably in attempting to retrieve Music Library content via the AVFoundation.
I have also failed in supplying content retrieved via the Media Player framework to the AVFoundation player.
(Note: The URLs retrieved from MPMediaItem are of a bogus "ipod-library://item/item.m4a?id=#########################" format. Creating AVPlayerItem with this "URL" doesn't work.)
Has anyone managed to accomplish this? I'm developing for my own usage. I have no intention of posting the app in Apple's App Store, so I'm willing to use hidden APIs or un-Apple approved methodology.
A Swift code example would be great. (Objective-C not so much)
Having fetched an MPMediaItem from the user's library, obtain its assetURL. Creating an AVPlayer from the resulting URL does work.
Actual code from one of my example apps:
func oneSong () -> (URL?, String?) {
let query = MPMediaQuery.songs()
// always need to filter out songs that aren't present
let isPresent = MPMediaPropertyPredicate(value:false,
forProperty:MPMediaItemPropertyIsCloudItem,
comparisonType:.equalTo)
query.addFilterPredicate(isPresent)
let item = query.items?[0]
return (item?.assetURL, item?.title)
}
#IBAction func doPlayOneSongAVPlayer (_ sender: Any) {
let (url, title) = self.oneSong()
if let url = url, let title = title {
self.avplayer = AVPlayer(url:url)
self.avplayer.play()
MPNowPlayingInfoCenter.default().nowPlayingInfo = [
MPMediaItemPropertyTitle : title
]
}
}

iOS (Swift) App Fails to Load 251st Sound Resource

After loading two or more audio files 250 times, the app fails to load further files. This appears to happen regardless of the length of the audio files or the duration between consecutive plays.
Error:
SKAction: Error loading sound resource: "audio/1.mp3"
Code (GameScene.swift):
import GameplayKit
class GameScene: SKScene {
var count = 0
override func didMove(to view: SKView) {
infiniteLoop()
}
func infiniteLoop() {
let number = count % 3 + 1
let playLetter = SKAction.playSoundFileNamed("audio/\(number).mp3", waitForCompletion: true)
self.run(playLetter, completion: {
self.count += 1
print(self.count)
self.infiniteLoop()
})
}
}
Audio Files (example):
http://s000.tinyupload.com/index.php?file_id=87262242252758332431
Reproducing The Error:
The error appears to be reproducible by simply making a new iOS game in Xcode, copying the "audio" (assets) folder linked above into the root of the project, and copying the code above into the GameScene.swift file. After getting to "250" in the console the error will likely appear.
Analysis:
After cycling through two or more audio files 250 times, the app fails to load the audio resource. I encountered this problem while making a spelling game which cycles through images and audio files in a similar manner. The problem originally presented itself by failing to load both the image files and the audio files after the app being used for ~15 minutes. I've managed to strip the app down to this core code and still trigger the error regardless of whether I simulate on my computer, simulate on my iPad, or even export and install (Ad Hoc) on my iPad.
I'm new to Swift and am hoping there is something simple at play here. Please let me know if you have any suggestions on how to fix this error.
Turns out the answer is to use AVAudioPlayer instead of SKAction for playing the audio file if it is to be played a large number of times.

How to get total No. of players from Leaderboard

Is there any way I can get how many player has played my game and successfully reported the score on Leaderboard?
I am currently working on Marmalade for iOS, so I'd prefer if you can let me know the solution in Marmalade. But if not possible, kindly let me know the solution at least in Objective C.
Finally found the solution after searching in the marmalade example. Following is the steps for to get the total count -
1.First you need to authenticate the player to gamecenter, it's like Login. THe authentication method is -
s3eIOSGameCenterAuthenticate(AuthenticationCallback, NULL);
2.Next we need to load the scores from the leaderboard
s3eIOSGameCenterLeaderboardLoadScores(leaderboard,loadScoreCallBack);
3.Now in the callback method i.e. loadScoreCallBack, you will get the TotalCount.
void loadScoreCallBack(s3eIOSGameCenterLoadScoresResult* result)
{
int TotalCount= result->m_ScoreCount;
}

Resources