React-native-youtube: Cannot get videosIndex value from Promise - IOS

Created on 16 Oct 2017  路  4Comments  路  Source: davidohayon669/react-native-youtube

Inside getProgress(e), I'm calling const vId = this._youTubeRef.videosIndex();

However the Promise is returning the following and I can't figure out how to extract the actual index.

Promise {_40: 0, _65: 0, _55: null, _72: null}
_40: 0
_55: 4
_65: 1
_72: null

I know that _55 is storing the Index Value as I can move through the track index and it changes as I change the current played track.

I just don't know how to get to it!...

I've tried all sorts of ways to get the value, but cannot figure it out - anyone know how to extract it?

Many thanks....

Most helpful comment

That's brilliant! I'm a bit new to javascript, however this is really well explained and makes perfect sense.

this._youTubeRef.videosIndex().then(function(result){
console.log(result);
});

I was going to suggest putting an example in the docs and when I looked there it was!...

Many thanks...

All 4 comments

@serialbandicoot videosIndex() returns a Promise, and promises needs to be chained with .then(), or being await-ed inside an async function.
What you are setting vId to is only the promise itself, not the resolved value of it.

That's brilliant! I'm a bit new to javascript, however this is really well explained and makes perfect sense.

this._youTubeRef.videosIndex().then(function(result){
console.log(result);
});

I was going to suggest putting an example in the docs and when I looked there it was!...

Many thanks...

I had the same problem and solved using then problems.
res.text().then((result)=>{ console.log(result); })

res is my promise data

I had the same problem and solved using then problems.
res.text().then((result)=>{ console.log(result); })

res is my promise data

If i want to return the res.text , how can i do? Please can you post

Was this page helpful?
0 / 5 - 0 ratings